Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
feat(api): introduce virtual model ID and description for model endpoints
myhlolif504cff8b077
diff --git a/docs/next/api/chat.md b/docs/next/api/chat.mdindex 9832ee55..a52afc69 100644--- a/docs/next/api/chat.md+++ b/docs/next/api/chat.md@@ -17,7 +17,7 @@ Chat Completions 和 Responses 面向细粒度文档理解场景,例如单张```json{- "model": "MinerU2.5-Pro-2605-1.2B",+ "model": "mineru-4.0.11","messages": [{"role": "user",@@ -48,7 +48,8 @@ Chat Completions 和 Responses 面向细粒度文档理解场景,例如单张| 字段 | 类型 | 必填 | 说明 ||------|------|:--:|------|| `messages` | array | 是 | 消息列表。 |-| `model` | string | 是 | 模型 ID,来自 `GET /v1/models`。 |+| `model` | string | 是 | 虚拟模型 ID(`mineru-<服务版本>`),来自 `GET /v1/models`,精确匹配当前部署广告值;不用于选择引擎。 |+| `tier` | string | 否 | MinerU 扩展字段:解析质量档(`flash`/`basic`/`standard`/`advanced`),内部复用 parse job 的 tier 路由与默认选择策略。OpenAI SDK 通过 `extra_body` 传入。 || `stream` | bool | 否 | 是否流式输出,默认 `false`。 || `stream_options.include_usage` | bool | 否 | `stream=true` 时,最终 chunk 是否包含 usage。 || `temperature` | number | 否 | 采样温度,范围 `[0, 2]`。 |@@ -97,7 +98,7 @@ Chat Completions 和 Responses 面向细粒度文档理解场景,例如单张"id": "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT","object": "chat.completion","created": 1741569952,- "model": "MinerU2.5-Pro-2605-1.2B",+ "model": "mineru-4.0.11","system_fingerprint": "fp_44709d6fcb","choices": [{@@ -137,9 +138,9 @@ Chat Completions 和 Responses 面向细粒度文档理解场景,例如单张`stream=true` 时返回 SSE,每行 `data:` 后是一个 `chat.completion.chunk` JSON 对象,最后以 `data: [DONE]` 结束。```text-data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"MinerU2.5-Pro-2605-1.2B","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}+data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"mineru-4.0.11","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}-data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"MinerU2.5-Pro-2605-1.2B","choices":[{"index":0,"delta":{"content":"# 文本"},"finish_reason":null}]}+data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"mineru-4.0.11","choices":[{"index":0,"delta":{"content":"# 文本"},"finish_reason":null}]}data: [DONE]```@@ -178,7 +179,7 @@ Chat 错误:```json{- "model": "MinerU2.5-Pro-2605-1.2B",+ "model": "mineru-4.0.11","input": [{"role": "user",@@ -236,7 +237,7 @@ Content part:"object": "response","created_at": 1741476542,"status": "completed",- "model": "MinerU2.5-Pro-2605-1.2B",+ "model": "mineru-4.0.11","output": [{"type": "message",diff --git a/docs/next/api/health-models.md b/docs/next/api/health-models.mdindex 50b46bfa..05e7aee8 100644--- a/docs/next/api/health-models.md+++ b/docs/next/api/health-models.md@@ -63,46 +63,31 @@ GET /v1/models HTTP/1.1"object": "list","data": [{- "id": "MinerU-Flash",- "object": "model",- "created": 1700000000,- "owned_by": "mineru"- },- {- "id": "Hybrid-Basic",- "object": "model",- "created": 1700000000,- "owned_by": "mineru"- },- {- "id": "MinerU-HTML",- "object": "model",- "created": 1700000000,- "owned_by": "mineru"- },- {- "id": "MinerU2.5-Pro-2605-1.2B",+ "id": "mineru-4.0.11","object": "model","created": 1700000000,"owned_by": "mineru",- "description": null+ "description": "MinerU virtual model. Quality is selected per request via tier (flash|basic|standard|advanced); this id identifies the server version, not a specific engine."}]}```-- 描述性 tier 文案(如 `Standard parsing for most documents.`)属于 `/v1/tiers` 返回的 tier info;`/v1/models` 的 `description` 当前为 `null`。-Local Parse Server 默认(`--tier standard`)按上述顺序返回 `MinerU-Flash`、`Hybrid-Basic`、`MinerU-HTML`、`MinerU2.5-Pro-2605-1.2B`;实际模型列表由启动 `--tier` 与 tier 禁用开关决定。禁用 Advanced 后,Standard 仍需使用的共享模型不会从列表移除。+- `/v1/models` 只广告一个**虚拟模型**:id 为 `mineru-<服务版本>`,标识服务端版本,不对应任何可单独调用的引擎。解析质量始终通过 parse job 的 `tier` 字段选择,模型 id 不参与路由。+- `created` 为该部署的注册时间(本地 server 取进程启动时刻),同一部署内多次请求返回相同值。+- 模型列表与启动 `--tier`、tier 禁用开关无关:档位增减只反映在 `/v1/tiers`,虚拟模型恒在列表中。+- 服务端升级后 id 随版本变化(如 `mineru-4.0.11` → `mineru-4.0.12`)。客户端应重新发现,不要缓存 id 硬编码进请求。+- 历史上广告过的 `MinerU-Flash`、`Hybrid-Basic`、`MinerU-HTML`、`MinerU2.5-Pro-2605-1.2B` 已从列表移除;这些名字从来不是可传入的参数。其中 `MinerU2.5-Pro-2605-1.2B` 仍是 standard/advanced 档背后的真实 VLM 权重仓库名,只是不再出现在本 endpoint。模型对象字段:| 字段 | 类型 | 必带 | 说明 ||------|------|:--:|------|-| `id` | string | 是 | 模型 ID。 |+| `id` | string | 是 | 虚拟模型 ID,`mineru-<服务版本>`。 || `object` | string | 是 | 固定为 `"model"`。 |-| `created` | integer | 是 | Unix 秒级时间戳,表示模型首次上线或被当前部署注册的时间。 |+| `created` | integer | 是 | Unix 秒级时间戳,表示被当前部署注册的时间。 || `owned_by` | string | 是 | 官方 API 固定为 `"mineru"`;自部署可使用组织名。 |-| `description` | string | 否 | 模型说明。 |+| `description` | string | 否 | 模型说明,注明虚拟模型语义与 tier 路由方式。 |## GET `/v1/models/{model}`@@ -111,21 +96,23 @@ Local Parse Server 默认(`--tier standard`)按上述顺序返回 `MinerU-Fl请求:```http-GET /v1/models/MinerU2.5-Pro-2605-1.2B HTTP/1.1+GET /v1/models/mineru-4.0.11 HTTP/1.1```响应:```json{- "id": "MinerU2.5-Pro-2605-1.2B",+ "id": "mineru-4.0.11","object": "model","created": 1700000000,"owned_by": "mineru",- "description": null+ "description": "MinerU virtual model. Quality is selected per request via tier (flash|basic|standard|advanced); this id identifies the server version, not a specific engine."}```+仅接受当前部署广告的虚拟模型 id(精确匹配),其余一律 404;服务端升级后旧版本 id 同样返回 404,客户端应重新发现。+错误:| HTTP | code | 场景 |@@ -151,7 +138,7 @@ GET /v1/tiers HTTP/1.1{"id": "standard","description": null,- "current_model": "MinerU2.5-Pro-2605-1.2B"+ "current_model": "mineru-4.0.11"}]}@@ -163,7 +150,7 @@ Tier 对象字段:|------|------|:--:|------|| `id` | string | 是 | 当前服务提供的真实质量 tier,例如 `basic`、`standard` 或 `advanced`。 || `description` | string | 是 | 档位说明。 |-| `current_model` | string 或 null | 是 | 当前 tier 背后的模型 ID。 |+| `current_model` | string 或 null | 是 | 当前 tier 背后的模型 ID,与 `/v1/models` 广告的虚拟模型一致:各档共用同一 id,差异由 `id`(档位)表达。 |## Tier 选择语义@@ -206,6 +193,8 @@ Local Parse Server 的 `health` 通常返回:本地或兼容服务应以 `/v1/tiers` 返回值作为能力发现事实。客户端不应根据启动参数猜测具体能力。+本地 `GET /v1/models` 恒返回当前版本的单一虚拟模型。经 Router 聚合多 worker 时,不同版本的 worker 会各自贡献 `mineru-<version>` 条目:Router 的 `/v1/models` 出现多个 `mineru-*` id 表示集群内存在版本漂移(滚动升级未完成),属预期诊断信号而非错误。+如果本地 server 支持 `flash`,它可以用于显式 `flash`、仅支持 flash tier 的输入归一化、watch 或索引机制,但不应出现在 PDF/image 面向用户质量解析的默认选择候选中。`mineru.net/api` 在相当长时间内只提供 `standard`。远端 `/v1/tiers` 因此应返回 `standard`;省略 `tier` 或传 `null` 等价于使用 `standard`。diff --git a/docs/next/api/parse-jobs.md b/docs/next/api/parse-jobs.mdindex 152d80ba..ae91473b 100644--- a/docs/next/api/parse-jobs.md+++ b/docs/next/api/parse-jobs.md@@ -222,7 +222,7 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定"page_range": "1-12","status": "completed","parse": {- "model_used": "MinerU2.5-Pro-2605-1.2B",+ "model_used": "mineru-4.0.11","duration_ms": 8234,"parser_version": "3.1.14"},diff --git a/mineru/parser/api_server.py b/mineru/parser/api_server.pyindex 8a952650..91f95b93 100644--- a/mineru/parser/api_server.py+++ b/mineru/parser/api_server.py@@ -311,6 +311,14 @@ class HealthResponse(BaseModel):# ── Models API ───────────────────────────────────────────────────────+# /v1/models 只广告一个虚拟模型:id 随服务版本走,解析质量由请求 tier 选择,+# 不对应任何可单独调用的引擎。+_VIRTUAL_MODEL_ID = f"mineru-{__version__}"+_VIRTUAL_MODEL_DESCRIPTION = (+ "MinerU virtual model. Quality is selected per request via tier (flash|basic|standard|advanced); "+ "this id identifies the server version, not a specific engine."+)+class ModelInfo(BaseModel):model_config = _PYDANTIC_CONFIG@@ -1652,9 +1660,9 @@ async def list_models(request: Request) -> ModelListResponse:"""List all available parsing models."""_require_model_preload_ready(request)model_ids: list[str] = request.app.state.model_ids- now = int(time.time())+ registered_at: int = request.app.state.model_registered_atreturn ModelListResponse(- data=[ModelInfo(id=mid, created=now) for mid in model_ids],+ data=[ModelInfo(id=mid, created=registered_at, description=_VIRTUAL_MODEL_DESCRIPTION) for mid in model_ids],)@@ -1679,8 +1687,7 @@ async def get_model(code="model_not_found",message=f"Model '{model}' not found",)- now = int(time.time())- return ModelInfo(id=model, created=now)+ return ModelInfo(id=model, created=request.app.state.model_registered_at, description=_VIRTUAL_MODEL_DESCRIPTION)# ── Tiers ────────────────────────────────────────────────────────────@@ -2107,52 +2114,45 @@ def _runtime_options_for_server_tiers(tiers: list[Tier]) -> dict[Tier, ParserRunreturn {tier: runtime_options_for_tier(tier) for tier in tiers}-def _model_ids_and_tiers_for_server_tier(tier: Tier) -> tuple[list[str], list[TierInfoData]]:+def _tiers_for_server_tier(tier: Tier) -> list[TierInfoData]:+ """单档请求 tier 的展示 metadata;current_model 统一指向唯一虚拟模型。"""if tier == "flash":- return ["MinerU-Flash"], [+ return [{"id": "flash","description": "Fast local text extraction.",- "current_model": "flash",+ "current_model": _VIRTUAL_MODEL_ID,},]if tier == "basic":- return ["Hybrid-Basic", "MinerU-HTML"], [+ return [{"id": "basic","description": "Basic parsing with local lightweight models.",- "current_model": "hybrid-basic",+ "current_model": _VIRTUAL_MODEL_ID,},]if tier == "advanced":- return ["MinerU2.5-Pro-2605-1.2B", "MinerU-HTML"], [+ return [{"id": "advanced","description": "Advanced parsing for difficult documents.",- "current_model": "MinerU2.5-Pro-2605-1.2B",+ "current_model": _VIRTUAL_MODEL_ID,},]- return ["MinerU2.5-Pro-2605-1.2B", "MinerU-HTML"], [+ return [{"id": "standard","description": "Standard parsing for most documents.",- "current_model": "MinerU2.5-Pro-2605-1.2B",+ "current_model": _VIRTUAL_MODEL_ID,},]-def _model_ids_and_tiers_for_server_tiers(tiers: list[Tier]) -> tuple[list[str], list[TierInfoData]]:- """聚合展开后的请求 tier metadata,并对重复 model id 保序去重。"""- model_ids: list[str] = []- tier_infos: list[TierInfoData] = []- for tier in tiers:- tier_model_ids, single_tier_infos = _model_ids_and_tiers_for_server_tier(tier)- for model_id in tier_model_ids:- if model_id not in model_ids:- model_ids.append(model_id)- tier_infos.extend(single_tier_infos)- return model_ids, tier_infos+def _tiers_for_server_tiers(tiers: list[Tier]) -> list[TierInfoData]:+ """展开后的请求 tier metadata。"""+ return [tier_info for tier in tiers for tier_info in _tiers_for_server_tier(tier)]def _preflight_tier_dependencies(tier: ServerTier, vlm_config: VlmConfig | None = None) -> None:@@ -2321,7 +2321,8 @@ def create_app(if max_url_bytes < 0:raise ValueError("max_url_bytes must be non-negative")- _model_ids, _tiers = _model_ids_and_tiers_for_server_tiers(server_tiers)+ _tiers = _tiers_for_server_tiers(server_tiers)+ _model_registered_at = int(time.time())_preload_tier: DeploymentTier | None = Noneif preload_models and tier != "flash":_preload_tier = tier@@ -2333,7 +2334,8 @@ def create_app(application.state.default_tier = default_tierapplication.state.flash_enabled = not no_flashapplication.state.tier_runtime_options = tier_runtime_options- application.state.model_ids = _model_ids+ application.state.model_ids = [_VIRTUAL_MODEL_ID]+ application.state.model_registered_at = _model_registered_atapplication.state.tiers = _tiersapplication.state.concurrency = concurrencyapplication.state.url_timeout = url_timeout@@ -2397,7 +2399,8 @@ def create_app(application.state.default_tier = default_tierapplication.state.flash_enabled = not no_flashapplication.state.tier_runtime_options = tier_runtime_options- application.state.model_ids = _model_ids+ application.state.model_ids = [_VIRTUAL_MODEL_ID]+ application.state.model_registered_at = _model_registered_atapplication.state.tiers = _tiersapplication.state.concurrency = concurrencyapplication.state.url_timeout = url_timeoutdiff --git a/tests/unittest/test_parser_api_contract.py b/tests/unittest/test_parser_api_contract.pyindex f82fa749..36f26534 100644--- a/tests/unittest/test_parser_api_contract.py+++ b/tests/unittest/test_parser_api_contract.py@@ -2495,7 +2495,8 @@ def test_api_server_standard_no_flash_state_and_metadata(tmp_path: Path, monkeypassert app.state.effort == "high"assert app.state.flash_enabled is Falseassert [tier["id"] for tier in app.state.tiers] == ["basic", "standard", "advanced"]- assert app.state.model_ids == ["Hybrid-Basic", "MinerU-HTML", "MinerU2.5-Pro-2605-1.2B"]+ assert app.state.model_ids == [api_server._VIRTUAL_MODEL_ID]+ assert api_server._VIRTUAL_MODEL_ID == f"mineru-{api_server.__version__}"assert app.state.tier_runtime_options["basic"].effort == "medium"assert app.state.tier_runtime_options["standard"].effort == "high"assert app.state.tier_runtime_options["advanced"].effort == "xhigh"@@ -2541,6 +2542,7 @@ def test_api_server_standard_http_metadata(tmp_path: Path, monkeypatch: pytest.Mhealth_response = client.get("/v1/health")tiers_response = client.get("/v1/tiers")models_response = client.get("/v1/models")+ model_detail_response = client.get(f"/v1/models/{api_server._VIRTUAL_MODEL_ID}")assert health_response.status_code == 200assert health_response.json()["status"] == "ok"@@ -2549,20 +2551,47 @@ def test_api_server_standard_http_metadata(tmp_path: Path, monkeypatch: pytest.Massert "runtime" not in health_response.json()assert tiers_response.status_code == 200assert [tier["id"] for tier in tiers_response.json()["data"]] == ["flash", "basic", "standard", "advanced"]+ assert all(tier["current_model"] == api_server._VIRTUAL_MODEL_ID for tier in tiers_response.json()["data"])assert models_response.status_code == 200- assert [model["id"] for model in models_response.json()["data"]] == [- "MinerU-Flash",- "Hybrid-Basic",- "MinerU-HTML",- "MinerU2.5-Pro-2605-1.2B",- ]+ assert [model["id"] for model in models_response.json()["data"]] == [api_server._VIRTUAL_MODEL_ID]+ assert models_response.json()["data"][0]["description"] == api_server._VIRTUAL_MODEL_DESCRIPTION+ assert model_detail_response.status_code == 200+ assert model_detail_response.json()["id"] == api_server._VIRTUAL_MODEL_ID+ assert model_detail_response.json()["created"] == app.state.model_registered_at+++def test_api_server_models_created_is_stable_across_requests(+ tmp_path: Path,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """回归:created 是部署注册时间,两次请求之间不随墙钟跳动。"""+ _stub_api_server_dependency_preflight(monkeypatch)+ app = create_app(upload_dir=str(tmp_path), tier="standard")++ with TestClient(app) as client:+ first = client.get("/v1/models").json()["data"][0]["created"]+ second = client.get("/v1/models").json()["data"][0]["created"]++ assert first == second == app.state.model_registered_at+++def test_api_server_model_detail_rejects_unknown_id(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:+ """非虚拟模型 id 一律 404,包括历史上的引擎品牌名。"""+ _stub_api_server_dependency_preflight(monkeypatch)+ app = create_app(upload_dir=str(tmp_path), tier="standard")++ with TestClient(app) as client:+ response = client.get("/v1/models/MinerU2.5-Pro-2605-1.2B")++ assert response.status_code == 404+ assert response.json()["error"]["code"] == "model_not_found"def test_api_server_no_advanced_http_metadata_keeps_shared_models(tmp_path: Path,monkeypatch: pytest.MonkeyPatch,) -> None:- """验证能力接口隐藏 Advanced,同时保留 Standard 仍需使用的共享模型。"""+ """验证能力接口隐藏 Advanced;虚拟模型 id 不随档位开关变化。"""_stub_api_server_dependency_preflight(monkeypatch)app = create_app(upload_dir=str(tmp_path), tier="standard", no_advanced=True)@@ -2573,12 +2602,7 @@ def test_api_server_no_advanced_http_metadata_keeps_shared_models(assert tiers_response.status_code == 200assert [tier["id"] for tier in tiers_response.json()["data"]] == ["flash", "basic", "standard"]assert models_response.status_code == 200- assert [model["id"] for model in models_response.json()["data"]] == [- "MinerU-Flash",- "Hybrid-Basic",- "MinerU-HTML",- "MinerU2.5-Pro-2605-1.2B",- ]+ assert [model["id"] for model in models_response.json()["data"]] == [api_server._VIRTUAL_MODEL_ID]def test_api_server_model_preload_failure_keeps_health_diagnostics_and_rejects_capabilities(