Skip to content

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

Require file ids for API output downloads

jinzhenj8761d96ccae8
diff --git a/mineru/parser/api_client.py b/mineru/parser/api_client.py
index 5091ad6d..1a210108 100644
--- a/mineru/parser/api_client.py
+++ b/mineru/parser/api_client.py
@@ -402,17 +402,9 @@ async def _async_download_json(parser: MinerUApiParser, outputs: dict[str, Any])
def _download_bytes(parser: MinerUApiParser, ref: dict[str, Any]) -> bytes:
- # TEMP(2026-06-12): staging server may return {"url": "..."} instead of
- # {"file_id": "...", "bytes": ...}. Keep this branch until staging aligns.
- if ref.get("url"):
- with httpx.Client(timeout=httpx.Timeout(120, connect=30), follow_redirects=True, trust_env=parser._trust_env) as cli:
- r = cli.get(ref["url"])
- _check_download_response(r)
- return r.content
-
file_id = ref.get("file_id")
if not file_id:
- raise _V1APIError("invalid_response", "No file_id or url in output reference")
+ raise _V1APIError("invalid_response", "No file_id in output reference")
with httpx.Client(timeout=httpx.Timeout(120, connect=30), follow_redirects=True, trust_env=parser._trust_env) as cli:
r = cli.get(f"{parser._base}/v1/files/{file_id}/content", headers=parser._headers())
@@ -421,19 +413,9 @@ def _download_bytes(parser: MinerUApiParser, ref: dict[str, Any]) -> bytes:
async def _async_download_bytes(parser: MinerUApiParser, ref: dict[str, Any]) -> bytes:
- # TEMP(2026-06-12): staging server may return {"url": "..."} instead of
- # {"file_id": "...", "bytes": ...}. Keep this branch until staging aligns.
- if ref.get("url"):
- async with httpx.AsyncClient(
- timeout=httpx.Timeout(120, connect=30), follow_redirects=True, trust_env=parser._trust_env
- ) as cli:
- r = await cli.get(ref["url"])
- _check_download_response(r)
- return r.content
-
file_id = ref.get("file_id")
if not file_id:
- raise _V1APIError("invalid_response", "No file_id or url in output reference")
+ raise _V1APIError("invalid_response", "No file_id in output reference")
async with httpx.AsyncClient(
timeout=httpx.Timeout(120, connect=30), follow_redirects=True, trust_env=parser._trust_env
diff --git a/tests/unittest/test_parser_api_contract.py b/tests/unittest/test_parser_api_contract.py
index 487af2db..6c958a5d 100644
--- a/tests/unittest/test_parser_api_contract.py
+++ b/tests/unittest/test_parser_api_contract.py
@@ -239,6 +239,29 @@ def test_async_api_client_accepts_remote_pdf_info_json(monkeypatch: pytest.Monke
assert result.pages[0]._backend == "pipeline"
+def test_api_client_rejects_output_reference_without_file_id() -> None:
+ parser = MinerUApiParser(api_url="https://staging.mineru.org.cn/api", tier="standard")
+
+ with pytest.raises(api_client._V1APIError) as exc_info:
+ api_client._download_bytes(parser, {"url": "https://example.invalid/output.json", "bytes": 10})
+
+ assert exc_info.value.code == "invalid_response"
+ assert exc_info.value.message == "No file_id in output reference"
+
+
+def test_async_api_client_rejects_output_reference_without_file_id() -> None:
+ parser = MinerUApiParser(api_url="https://staging.mineru.org.cn/api", tier="standard")
+
+ async def _run() -> None:
+ await api_client._async_download_bytes(parser, {"url": "https://example.invalid/output.json", "bytes": 10})
+
+ with pytest.raises(api_client._V1APIError) as exc_info:
+ asyncio.run(_run())
+
+ assert exc_info.value.code == "invalid_response"
+ assert exc_info.value.message == "No file_id in output reference"
+
+
@pytest.mark.parametrize("image_path", ["../escape.png", "/tmp/escape.png", "\\escape.png", "C:\\escape.png"])
def test_api_client_rejects_unsafe_image_sidecar_paths(
monkeypatch: pytest.MonkeyPatch,