MinerU API Server#
mineru-kit api-server is a FastAPI/uvicorn HTTP service that exposes MinerU's document-parsing pipeline over a versioned REST API (/v1/*). The implementation lives in mineru/parser/api_server.py, launched via the mineru-kit CLI entry point registered at mineru/kit/commands/api_server.py.
Server Startup & Port Configuration#
The api_server_cmd CLI command (delegating to main()) accepts:
| Option | Default | Notes |
|---|---|---|
--host | 127.0.0.1 | Set to 0.0.0.0 for public binding |
--port | 8000 | Any free integer port |
--concurrency | 1 | Max concurrent parse jobs |
--vlm-max-concurrency | 100 (from VlmConfig) | VLM inference concurrency cap |
--tier | standard | Worker tier: flash, basic, standard |
--preload-models | off | Preloads models at startup |
--retention-seconds | 86400 | Retention for finished tasks and their artifacts; 0 disables automatic collection. Also settable via MINERU_API_RETENTION_SECONDS; also accepted by mineru-kit router |
/docs, /redoc and /openapi.json are enabled by default. Their JS/CSS/icons are served locally under /docs/assets (via the fastapi-offline dependency) and work behind a proxy root_path. Setting MINERU_API_ENABLE_FASTAPI_DOCS=false disables both the doc endpoints and the asset mounting.
The app is built by create_app() and served by uvicorn.
Concurrency Control#
Parse-job concurrency is enforced by a per-process asyncio.Semaphore inside JobStore, clamped to a minimum of 1. Each submitted job enters async with self._semaphore before executing, so excess jobs wait in queue rather than running concurrently.
The default --concurrency 1 means only one parse runs at a time per server process. Raising it (e.g., --concurrency 5) allows parallel jobs but introduces risk of lock contention — see Known Issues below.
Health Check Protocol#
GET /v1/health returns HTTP 200 with:
{
"status": "ok",
"version": "<semver>",
"features": {
"webhook": false,
"output_formats": ["markdown", "middle_json", "structured_content", "zip"],
"sources": ["file_id", "url", "inline"]
}
}
HTTP 503 is returned when startup model preloading is enabled and fails — specifically when app.state.model_preload_error is set — or when the local engine has died (see Engine Death). Apart from explicit engine death, this health check is a model-readiness gate, not a liveness probe for active parse jobs.
Engine Death#
An explicit local engine death (e.g. vLLM EngineDeadError) makes the health check and new submissions return HTTP 503 with error code engine_dead. The running task is cancelled after cleanup and queued tasks fail; a user-initiated cancel remains canceled. Ordinary parse errors and remote timeouts do not count as engine death.
Under mineru-kit router, the failed worker is removed immediately. Managed worker processes are rebuilt with 5/10/20/30s backoff on failed restarts, and external workers are recovered by their owners. Unfinished tasks from the old worker generation keep a failure snapshot until they expire.
Critical gap: A parse job can become permanently stuck (job status
running,finished_at: null, subsequent jobsqueued) while/v1/healthcontinues returning 200. This has been observed in v4.0.4 after all model inference stages complete (Layout 100%, VLM 100%, OCR 100%), with zero GPU utilization and no error output. Container restart is the only recovery.
Task Endpoints#
| Method | Path | Behavior |
|---|---|---|
POST /v1/parse/jobs | Submit a new parse job | Returns job_id immediately (HTTP 202) |
GET /v1/parse/jobs/{job_id} | Poll job status | Returns status, progress, and file states |
GET /v1/parse/jobs/{job_id}/result | Fetch result | Available once status == "done" |
Both mineru-kit api-server and mineru-kit router also serve self-hosted convenience routes. They share tasks with /v1/parse/jobs: task_id equals the job_id. There are no root /tasks or /file_parse routes. Whether the official cloud service supports these routes is deployment-specific.
| Method | Path | Behavior |
|---|---|---|
POST /v1/tasks | Submit a task asynchronously | Returns HTTP 202 with status and query URLs |
GET /v1/tasks/{task_id} | Poll task status | Returns status, progress, and per-file result references |
GET /v1/tasks/{task_id}/result | Fetch result | JSON, or a ZIP via response_format=zip |
DELETE /v1/tasks/{task_id} | Cancel the task | Cancels the underlying background task |
POST /v1/file_parse | Synchronous wrapper | Submits a task, waits up to wait_timeout (1–3600 seconds, default 300) and returns the result directly |
When the wait_timeout budget runs out, POST /v1/file_parse returns HTTP 202 with task_id, status_url and result_url; the task keeps running.
Multi-Instance Deployment with mineru-kit router#
mineru-kit router (defined in mineru/kit/router/cli.py) is the load balancer coordinating one or more api-server instances.
Router defaults: host 127.0.0.1, port 8002.
Worker Sources#
Workers are either remote or local-GPU managed:
- Remote workers: passed via
--upstream-url(repeatable). - Local GPU workers:
--local-gpus auto|none|<CSV>spawns oneapi-serverprocess per GPU, each with--worker-concurrency(default1) passed as--concurrency. - Worker tier:
--worker-tier(flash,basic,standard; defaultstandard).
Health Monitoring & Restart#
The router polls each worker's /v1/health every 2 seconds (DEFAULT_WORKER_REFRESH_INTERVAL_SECONDS). A local worker is restarted when its process is missing or has exited (as detected by process.poll()). Health-check request failures mark the worker unhealthy but do not by themselves trigger a restart — the exit condition is process death, not health failure count. The exception is an engine_dead 503, which removes the worker immediately and, for managed workers, requests a rebuild (see Engine Death).
The router's own GET /v1/health aggregates features from healthy workers and returns 503 when no healthy workers exist.
Load Balancing#
Worker selection (select) is load-aware rather than tied to credential/IP affinity. It filters by health and capability (tier, source features, output formats), then compares (active_jobs / max_concurrent_jobs, active_jobs) and round-robins among workers tied for the lowest load. Source-file ownership is only a preference among the lowest-load candidates. Upload and task selection use independent cursors.
Counts are reserved before the upstream task is created and released exactly once. A batch task goes to a single worker. Managed worker capacity comes from --worker-concurrency; external workers weigh as capacity 1.
Example Docker Compose Topology#
# Single-GPU api-server
mineru-kit api-server --host 0.0.0.0 --port 8000
# Multi-GPU router spawning one worker per GPU
mineru-kit router --host 0.0.0.0 --port 8002 --local-gpus auto \
--worker-tier standard --worker-concurrency 1 --preload-models
# Router aggregating existing api-servers
mineru-kit router --local-gpus none \
--upstream-url http://api1:8000 --upstream-url http://api2:8000
Known Issues#
Stuck Jobs Block the Queue#
A parse job can stall permanently after all model inference stages complete, holding the semaphore slot and leaving all subsequent jobs queued indefinitely. The /v1/health endpoint continues returning 200 during the stall. Container restart is required to recover.
Lock Contention at --concurrency > 1#
When --concurrency is raised above 1, a per-device RLock in mineru/model/runtime/execution.py (local_model_stage) is held across the PDF render stage — a wait that can last minutes. One thread waiting on render workers blocks every other parse job on the server, converting a slow document into a complete server stall. The lock's own docstring states it must not be held across the VLM wait. The default --concurrency 1 avoids this contention; set --concurrency > 1 only if you understand and accept the stall risk.
Key Files#
| File | Purpose |
|---|---|
mineru/parser/api_server.py | FastAPI app, JobStore, all API endpoints, main() CLI |
mineru/kit/commands/api_server.py | mineru-kit api-server CLI wrapper |
mineru/kit/router/cli.py | mineru-kit router CLI and mineru-router entry point |
mineru/kit/router/workers.py | WorkerPool, health monitor, worker selection, RouterSettings |
mineru/kit/router/app.py | Router FastAPI app and /v1/health aggregation |