Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

Remove parse job wait support

jinzhenjbd939bfdbb25
diff --git a/docs/next/api.md b/docs/next/api.md
index 464d3d8f..1d4e38c0 100644
--- a/docs/next/api.md
+++ b/docs/next/api.md
@@ -21,7 +21,7 @@ Unified API 文档描述两类部署形态下的同一套 API:
2. [响应与错误](api/responses.md): 成功响应、错误 envelope、请求追踪。
3. [Health、Models 与 Tiers](api/health-models.md): 服务能力、模型列表、解析档位。
4. [Uploads 与 Files](api/uploads-files.md): 上传生命周期、文件对象、产物下载。
-5. [Parse Jobs](api/parse-jobs.md): 解析任务、同步等待、轮询、SSE。
+5. [Parse Jobs](api/parse-jobs.md): 解析任务、轮询、SSE。
6. [Chat 与 Responses](api/chat.md): OpenAI-compatible 文档对话接口。
7. [Webhooks](api/webhooks.md): 异步回调协议。
8. [Usage 与 Limits](api/usage-limits.md): access level、限流、用量查询。
diff --git a/docs/next/api/changes.md b/docs/next/api/changes.md
new file mode 100644
index 00000000..ed192fe9
--- /dev/null
+++ b/docs/next/api/changes.md
@@ -0,0 +1,19 @@
+# API 变更记录
+
+范围: NEXT v1 API 标准的破坏性或需要迁移的行为变化。
+
+## 2026-07-08: 删除 parse job `wait` 参数
+
+`POST /v1/parse/jobs` 不再支持 `wait`。创建 parse job 始终返回 `202` 和 job 引用,客户端通过 `GET /v1/parse/jobs/{job_id}` 查询状态和结果。
+
+API 不提供在创建请求中同步等待完成的模式,也不内联返回 Markdown 内容。所有产物内容仍通过 `output_files` 对应的 File API 下载。
+
+这样可以避免线上服务长连接阻塞和本地/线上实现差异,让 parse job 保持单一异步模型。
+
+## 2026-07-08: 删除独立 `images` 输出格式
+
+`images` 不再是 `POST /v1/parse/jobs` 的合法 `output_formats` 值,parse job 响应中也不再返回 `output_files.images`。
+
+图片 sidecar 只通过 `zip` 产物返回。`markdown`、`middle_json`、`content_list`、`structured_content` 输出仍可能包含 `image_path` 引用,但这些引用对应的图片字节不再作为独立 parse output 暴露。
+
+这样可以避免同一批图片同时通过独立 output 和 zip 两条路径返回,减少产物语义重复,并让需要自包含解析结果的客户端统一依赖 `zip`。
diff --git a/docs/next/api/examples.md b/docs/next/api/examples.md
index b3ffcdfc..d45f672c 100644
--- a/docs/next/api/examples.md
+++ b/docs/next/api/examples.md
@@ -80,24 +80,6 @@ curl -L "https://mineru.net/api/v1/files/$MD_FILE_ID/content" \
实际客户端应使用指数退避轮询,最大间隔建议 30 秒。
-## 官方 API: 同步等待 Markdown
-
-```bash
-curl -X POST https://mineru.net/api/v1/parse/jobs \
- -H "Authorization: Bearer $MINERU_API_KEY" \
- -H "Content-Type: application/json" \
- -d "{
- \"files\": [{
- \"source\": {\"type\":\"file_id\",\"file_id\":\"$FILE_ID\"}
- }],
- \"tier\": null,
- \"output_formats\": [\"markdown\",\"middle_json\"],
- \"wait\": 30
- }"
-```
-
-30 秒内完成时返回 `200`,响应中包含 `output_files` 产物引用。客户端仍通过 `GET /v1/files/{file_id}/content` 获取内容。超时则返回 `202`,客户端继续轮询 `GET /v1/parse/jobs/{job_id}`。
-
## 官方 API: URL 来源
```bash
@@ -143,8 +125,7 @@ curl -X POST http://localhost:8000/api/v1/parse/jobs \
"source": {"type":"local","path":"/data/docs/report.pdf"}
}],
"tier": null,
- "output_formats": ["markdown"],
- "wait": 120
+ "output_formats": ["markdown"]
}'
```
diff --git a/docs/next/api/parse-jobs.md b/docs/next/api/parse-jobs.md
index bd3d092a..1acf3d0e 100644
--- a/docs/next/api/parse-jobs.md
+++ b/docs/next/api/parse-jobs.md
@@ -2,7 +2,7 @@
状态: Draft
读者: API 使用者、服务端开发者、SDK 开发者
-范围: 解析任务创建、查询、同步等待、轮询和事件流
+范围: 解析任务创建、查询、轮询和事件流
来源: 由根目录旧 Unified API 底稿迁移整理而来
## 任务模型
@@ -39,7 +39,6 @@ Job 状态:
],
"tier": null,
"output_formats": ["markdown", "middle_json", "structured_content", "zip"],
- "wait": 30,
"callback": {
"url": "https://your.app/mineru-webhook",
"secret": "abc123"
@@ -54,7 +53,6 @@ Job 状态:
| `files` | array | 是 | 无 | 至少 1 个,最多由 access level 决定。 |
| `tier` | string 或 null | 否 | `null` | `medium`、`high` 或 `null`。省略或传 `null` 表示使用默认选择策略,选择当前可发现的最高质量非 `flash` tier。HTML 输入自动路由到 HTML 解析器。 |
| `output_formats` | array | 否 | `["markdown"]` | 请求产物格式。 |
-| `wait` | integer | 否 | `0` | 同步等待秒数。`0` 表示立即异步返回。 |
| `callback` | object | 否 | `null` | Webhook 回调配置,官方 API registered 用户可用。 |
### `files[]`
@@ -139,22 +137,9 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定
`json`、`content_list_v2` 不是 NEXT 版正式格式名,不进入公开格式集合。命名决策见 [ADR-0001](../decisions/0001-json-output-formats.md)。
-### `wait`
+### 创建响应
-`wait` 控制创建任务时是否同步等待结果:
-
-| 值 | 行为 |
-|----|------|
-| `0` 或缺省 | 立即返回 `202`,客户端异步轮询。 |
-| `5` 到 `50` | 官方 API 最多阻塞等待 N 秒。完成则返回 `200`;超时返回 `202`。 |
-
-如果客户端连接在等待期间断开,job 不应被取消。服务端只停止向该连接写入,任务继续运行,客户端可用 job id 后续查询。
-
-官方 API 的 `wait` 上限设计为小于常见反向代理默认超时。本地 server 可以提供更高上限。
-
-### 异步响应
-
-`wait=0` 或等待超时时返回 `202`。
+创建成功时返回 `202`。客户端通过 `GET /v1/parse/jobs/{job_id}` 查询任务状态和结果。
```json
{
@@ -180,7 +165,7 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定
}
```
-异步响应字段:
+创建响应字段:
| 字段 | 类型 | 说明 |
|------|------|------|
@@ -195,9 +180,9 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定
| `links.events` | string 或 null | SSE URL;不支持 SSE 时可以为 `null` 或省略。 |
| `links.cancel` | string | 取消任务 URL。 |
-### 同步完成响应
+### 终态响应
-`wait > 0` 且任务在超时内完成时返回 `200`。
+`GET /v1/parse/jobs/{job_id}` 查询到终态任务时返回 `200`。
```json
{
@@ -262,7 +247,7 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定
## GET `/v1/parse/jobs/{job_id}`
-查询任务状态和结果。终态 job 使用与同步完成响应相同的结构,但只返回产物 File 引用,不返回产物内容。未完成 job 可以只返回当前 `status`、`progress` 和 `files` 的阶段信息。
+查询任务状态和结果。终态 job 使用与终态响应相同的结构,但只返回产物 File 引用,不返回产物内容。未完成 job 可以只返回当前 `status`、`progress` 和 `files` 的阶段信息。
轮询建议:
@@ -391,7 +376,6 @@ data: {"job_id":"job_01HXYZ...","status":"completed"}
Local Parse Server 的任务 API 与官方 API 保持同一结构,但有以下实现差异:
-- `wait` 上限可以高于公网,例如允许到 600 秒,以适配本机调用。
- 不支持 Webhook 时,`health.features.webhook` 必须为 `false`;收到 `callback` 时应返回 `400 invalid_request` 或明确忽略。
- 不支持 SSE 时,`health.features.sse` 必须为 `false`,`links.events` 可以为 `null` 或省略。
- 支持 `local` source,但必须限制在配置允许的根目录内。
diff --git a/docs/next/decisions/0017-mineru-kit-api-server-command.md b/docs/next/decisions/0017-mineru-kit-api-server-command.md
index 1bf9ef49..4076eea3 100644
--- a/docs/next/decisions/0017-mineru-kit-api-server-command.md
+++ b/docs/next/decisions/0017-mineru-kit-api-server-command.md
@@ -90,7 +90,6 @@ backend 不是普通 API 协议层字段。
- `--concurrency`
- `--upload-dir`
- `--url-timeout`
-- `--max-wait`
#### 专家参数
diff --git a/mineru/kit/commands/api_server.py b/mineru/kit/commands/api_server.py
index 7ac5b123..fd04ee87 100644
--- a/mineru/kit/commands/api_server.py
+++ b/mineru/kit/commands/api_server.py
@@ -39,7 +39,6 @@ def api_server_cmd(
| None = None,
concurrency: int = 1,
url_timeout: int = 60,
- max_wait: int = 600,
language: str = "ch",
ocr_mode: Literal["auto", "txt", "ocr"] = "auto",
disable_image_analysis: bool = False,
@@ -62,8 +61,6 @@ def api_server_cmd(
str(concurrency),
"--url-timeout",
str(url_timeout),
- "--max-wait",
- str(max_wait),
"--language",
normalized_language,
"--ocr-mode",
diff --git a/mineru/kit/main.py b/mineru/kit/main.py
index dc041ee7..e64763de 100644
--- a/mineru/kit/main.py
+++ b/mineru/kit/main.py
@@ -47,7 +47,11 @@ def parse_command(
remote: bool = typer.Option(False, "--remote", help="Use mineru.net official remote parse service"),
remote_url: str | None = typer.Option(None, "--remote-url", help="Use a custom remote parse service URL"),
api_key: str | None = typer.Option(None, "--api-key", help="API key for remote parse service"),
- language: str = typer.Option("ch", "--language", help="Hybrid medium OCR language hint; accepted by other efforts for compatibility"),
+ language: str = typer.Option(
+ "ch",
+ "--language",
+ help="Hybrid medium OCR language hint; accepted by other efforts for compatibility",
+ ),
ocr_mode: str = typer.Option("auto", "--ocr-mode", help="OCR mode: auto, txt, ocr"),
effort: str = typer.Option(DEFAULT_HYBRID_EFFORT, "--effort", help=HYBRID_EFFORT_HELP),
disable_image_analysis: bool = typer.Option(False, "--disable-image-analysis", help="Disable image analysis"),
@@ -83,8 +87,11 @@ def api_server_command(
),
concurrency: int = typer.Option(1, "--concurrency", help="Maximum concurrent parse jobs"),
url_timeout: int = typer.Option(60, "--url-timeout", help="Timeout for URL source downloads"),
- max_wait: int = typer.Option(600, "--max-wait", help="Maximum seconds for wait parameter"),
- language: str = typer.Option("ch", "--language", help="Hybrid medium OCR language hint; accepted by other efforts for compatibility"),
+ language: str = typer.Option(
+ "ch",
+ "--language",
+ help="Hybrid medium OCR language hint; accepted by other efforts for compatibility",
+ ),
ocr_mode: str = typer.Option("auto", "--ocr-mode", help="OCR mode: auto, txt, ocr"),
disable_image_analysis: bool = typer.Option(False, "--disable-image-analysis", help="Disable image analysis"),
api_key: str | None = typer.Option(None, "--api-key", help="Optional fixed API key"),
@@ -97,7 +104,6 @@ def api_server_command(
tier=tier, # type: ignore[arg-type]
concurrency=concurrency,
url_timeout=url_timeout,
- max_wait=max_wait,
language=language,
ocr_mode=ocr_mode, # type: ignore[arg-type]
disable_image_analysis=disable_image_analysis,
diff --git a/mineru/parser/api_client.py b/mineru/parser/api_client.py
index b3c146f2..4c08f4c1 100644
--- a/mineru/parser/api_client.py
+++ b/mineru/parser/api_client.py
@@ -236,7 +236,6 @@ class MinerUApiParser(DocumentParser):
r = cli.post(f"{self._base_url}/v1/parse/jobs", headers=self._headers(), json=payload)
job = self._check(r)
if job.get("status") not in _TERMINAL_JOB_STATUSES:
- # poll if wait timed out
job = self._poll(cli, job["job_id"])
return job
diff --git a/mineru/parser/api_server.py b/mineru/parser/api_server.py
index 99a78ba1..d6ad0227 100644
--- a/mineru/parser/api_server.py
+++ b/mineru/parser/api_server.py
@@ -456,7 +456,6 @@ class CreateJobRequest(BaseModel):
files: list[JobFileEntry] = Field(min_length=1)
tier: Tier | None = None
output_formats: list[OutputFormat] = ["markdown"]
- wait: int = Field(default=0, ge=0)
callback: CallbackConfig | None = None
@@ -1660,7 +1659,6 @@ async def delete_file(
response_model=None,
status_code=status.HTTP_202_ACCEPTED,
responses={
- 200: {"model": JobAsyncResponse},
202: {"model": JobAsyncResponse},
**_ERR_400,
**_ERR_403,
@@ -1703,16 +1701,6 @@ async def create_job(
message=f"Unknown output format: {fmt}",
)
- # validate wait vs server limit
- max_wait: int = request.app.state.max_wait
- if body.wait != 0 and (body.wait < 5 or body.wait > max_wait):
- _raise_api_error(
- 400,
- error_type="invalid_request_error",
- code="invalid_request",
- message=f"wait must be 0 or [5, {max_wait}]",
- )
-
# 按请求 tier 选择启动时预先解析好的 runtime,避免所有 job 共享默认 effort。
body.tier = body.tier or request.app.state.default_tier
runtime_options: dict[Tier, ParserRuntimeOptions] = request.app.state.tier_runtime_options
@@ -1733,35 +1721,6 @@ async def create_job(
effort_val = runtime.effort
image_analysis_val: bool = request.app.state.image_analysis
- if body.wait > 0:
- async with job_store._semaphore:
- task = asyncio.create_task(
- _run_job(
- rec,
- body,
- file_store,
- server_backend=backend,
- language=language_val,
- ocr_mode=ocr_mode_val,
- effort=effort_val,
- image_analysis=image_analysis_val,
- url_timeout=url_timeout_val,
- )
- )
- try:
- await asyncio.wait_for(task, timeout=body.wait)
- except asyncio.TimeoutError:
- pass
- if rec.status in ("completed", "partial"):
- return JSONResponse(
- content=job_store.build_response(rec).model_dump(by_alias=True),
- status_code=200,
- )
- return JSONResponse(
- content=job_store.build_response(rec).model_dump(by_alias=True),
- status_code=202,
- )
-
# async — fire and forget
async def _bg_run() -> None:
async with job_store._semaphore:
@@ -2029,7 +1988,6 @@ def create_app(
tier: Tier | list[Tier] | tuple[Tier, ...] | None = None,
concurrency: int = 1,
url_timeout: int = 60,
- max_wait: int = 600,
api_key: str | None = None,
language: str = "ch",
ocr_mode: str = "auto",
@@ -2048,8 +2006,6 @@ def create_app(
Maximum concurrent parse jobs (default 1).
url_timeout:
Timeout in seconds for downloading url sources (default 60).
- max_wait:
- Maximum seconds for the ``wait`` parameter (default 300).
api_key:
Optional API key. When set, clients must pass ``Authorization: Bearer <key>``
to access list endpoints and advanced output formats.
@@ -2089,7 +2045,6 @@ def create_app(
application.state.tiers = _tiers
application.state.concurrency = concurrency
application.state.url_timeout = url_timeout
- application.state.max_wait = max_wait
application.state.api_key = _api_key
application.state.language = language
application.state.ocr_mode = ocr_mode
@@ -2118,7 +2073,6 @@ def create_app(
application.state.tiers = _tiers
application.state.concurrency = concurrency
application.state.url_timeout = url_timeout
- application.state.max_wait = max_wait
application.state.api_key = _api_key
application.state.language = language
application.state.ocr_mode = ocr_mode
@@ -2220,12 +2174,6 @@ def create_app(
type=int,
help="Timeout in seconds for url source downloads (default: 60)",
)
- "--max-wait",
- default=600,
- type=int,
- help="Maximum seconds for the wait parameter (default: 600)",
-)
@click.option(
"--language",
default="ch",
@@ -2253,7 +2201,6 @@ def main(
tier: tuple[Tier, ...],
concurrency: int,
url_timeout: int,
- max_wait: int,
language: str,
ocr_mode: str,
disable_image_analysis: bool,
@@ -2266,7 +2213,6 @@ def main(
tier=tier or None,
concurrency=concurrency,
url_timeout=url_timeout,
- max_wait=max_wait,
api_key=api_key,
language=language,
ocr_mode=ocr_mode,
diff --git a/tests/unittest/test_parser_api_contract.py b/tests/unittest/test_parser_api_contract.py
index 46ef1f7d..fee1d9b9 100644
--- a/tests/unittest/test_parser_api_contract.py
+++ b/tests/unittest/test_parser_api_contract.py
@@ -1081,6 +1081,14 @@ def test_create_job_request_accepts_new_format_names_and_rejects_options() -> No
}
)
+ with pytest.raises(ValidationError):
+ CreateJobRequest.model_validate(
+ {
+ "files": [{"source": {"type": "local", "path": "/tmp/demo.pdf"}}],
+ "wait": 5,
+ }
+ )
+
with pytest.raises(ValidationError):
CreateJobRequest.model_validate(
{
@@ -1159,7 +1167,6 @@ def test_create_app_does_not_read_runtime_settings_from_env(tmp_path: Path, monk
monkeypatch.setenv("MINERU_BACKEND", "hybrid-auto-engine")
monkeypatch.setenv("MINERU_CONCURRENCY", "9")
monkeypatch.setenv("MINERU_URL_TIMEOUT", "99")
- monkeypatch.setenv("MINERU_MAX_WAIT", "999")
monkeypatch.setenv("MINERU_LANGUAGE", "en")
monkeypatch.setenv("MINERU_OCR_MODE", "ocr")
monkeypatch.setenv("MINERU_EFFORT", "high")
@@ -1173,7 +1180,6 @@ def test_create_app_does_not_read_runtime_settings_from_env(tmp_path: Path, monk
assert app.state.backend == "hybrid-engine"
assert app.state.concurrency == 1
assert app.state.url_timeout == 60
- assert app.state.max_wait == 600
assert app.state.language == "ch"
assert app.state.ocr_mode == "auto"
assert app.state.effort == "high"
@@ -1829,30 +1835,46 @@ def test_api_server_multi_tier_jobs_use_requested_tier_runtime(tmp_path: Path, m
source = tmp_path / "demo.pdf"
source.write_bytes(b"%PDF-1.7\n")
app = create_app(upload_dir=str(tmp_path / "api"), tier=["medium", "high"])
+ file_store = FileStore(tmp_path / "api-files")
+ job_store = api_server.JobStore()
- with TestClient(app) as client:
- default_response = client.post(
- "/v1/parse/jobs",
- json={
+ async def run_request(payload: dict[str, object]) -> dict[str, object]:
+ request = CreateJobRequest.model_validate(payload)
+ request.tier = request.tier or app.state.default_tier
+ runtime = app.state.tier_runtime_options[request.tier]
+ rec = job_store.create(request, file_store)
+ await api_server._run_job(
+ rec,
+ request,
+ file_store,
+ server_backend=runtime.backend,
+ language=app.state.language,
+ ocr_mode=app.state.ocr_mode,
+ effort=runtime.effort,
+ image_analysis=app.state.image_analysis,
+ )
+ return job_store.build_response(rec).model_dump(by_alias=True)
+
+ default_response = asyncio.run(
+ run_request(
+ {
"files": [{"source": {"type": "local", "path": str(source)}}],
"output_formats": ["middle_json"],
- "wait": 5,
- },
+ }
)
- medium_response = client.post(
- "/v1/parse/jobs",
- json={
+ )
+ medium_response = asyncio.run(
+ run_request(
+ {
"files": [{"source": {"type": "local", "path": str(source)}}],
"tier": "medium",
"output_formats": ["middle_json"],
- "wait": 5,
- },
+ }
)
+ )
- assert default_response.status_code == 200
- assert default_response.json()["tier"] == "high"
- assert medium_response.status_code == 200
- assert medium_response.json()["tier"] == "medium"
+ assert default_response["tier"] == "high"
+ assert medium_response["tier"] == "medium"
assert [(call["tier"], call["backend"], call["effort"]) for call in calls] == [
("high", "hybrid-engine", "high"),
("medium", "hybrid-engine", "medium"),
@@ -1872,7 +1894,6 @@ def test_api_server_single_tier_rejects_unavailable_tier(tmp_path: Path, monkeyp
json={
"files": [{"source": {"type": "local", "path": str(source)}}],
"tier": "extra_high",
- "wait": 0,
},
)