opendatalab/MinerU · error · HTTPException

Invalid parse_method. Allowed values: {allowed_values}

Error message

Invalid parse_method. Allowed values: {allowed_values}

What it means

HTTP 400 raised by the FastAPI parse endpoint's validate_parse_method(): the parse_method form field must be one of {'auto','txt','ocr'} (ALLOWED_PARSE_METHODS in mineru/cli/api_request.py). It exists so every public entry enforces one rule set instead of each endpoint drifting.

Source

Thrown at mineru/cli/api_request.py:58

    table_enable: bool
    image_analysis: bool
    server_url: Optional[str]
    return_md: bool
    return_middle_json: bool
    return_model_output: bool
    return_content_list: bool
    return_images: bool
    response_format_zip: bool
    return_original_file: bool
    client_side_output_generation: bool
    start_page_id: int
    end_page_id: int


def validate_parse_method(parse_method: str) -> str:
    """校验公开 API 允许的 PDF 解析方式,避免各入口维护不同规则。"""
    if parse_method not in ALLOWED_PARSE_METHODS:
        raise HTTPException(
            status_code=400,
            detail=(
                "Invalid parse_method. Allowed values: "
                + ", ".join(sorted(ALLOWED_PARSE_METHODS))
            ),
        )
    return parse_method


def validate_parse_backend(backend: str) -> str:
    """校验公开 API 允许的解析后端,避免旧入口名进入下游执行链路。"""
    try:
        return validate_public_backend(backend)
    except ValueError as exc:
        raise HTTPException(status_code=400, detail=str(exc)) from exc


def validate_parse_effort(effort: str) -> str:

View on GitHub (pinned to 4fe4bde114)

Solutions

  1. Use one of: auto, txt, ocr (exact lowercase) for parse_method
  2. To select the engine, use the separate backend parameter (pipeline, vlm-engine, hybrid-engine, ...) not parse_method
  3. Check the live schema at the server's /docs endpoint for the current field names
  4. Upgrade the client script to the mineru version matching the server

Example fix

# before
curl -F file=@doc.pdf -F parse_method=vlm http://localhost:8000/file_parse

# after
curl -F file=@doc.pdf -F parse_method=auto -F backend=vlm-engine http://localhost:8000/file_parse
Defensive patterns

Strategy: validation

Validate before calling

from mineru.cli.api_request import ALLOWED_PARSE_METHODS  # {'auto','txt','ocr'}

parse_method = parse_method.strip().lower()
if parse_method not in ALLOWED_PARSE_METHODS:
    raise SystemExit(f"parse_method must be one of {sorted(ALLOWED_PARSE_METHODS)}")

Type guard

def is_valid_parse_method(v: str) -> bool:
    return isinstance(v, str) and v.strip().lower() in {"auto", "txt", "ocr"}

Try / catch

try:
    resp = requests.post(url, files=files, data={"parse_method": pm, "backend": b}, timeout=60)
    resp.raise_for_status()
except requests.HTTPError as e:
    if e.response.status_code == 400 and "parse_method" in e.response.text:
        pm = "auto"  # retry with the safe default
        resp = requests.post(url, files=files, data={"parse_method": pm, "backend": b}, timeout=60)
    else:
        raise

Prevention

When it happens

Trigger: POSTing to /file_parse (or the equivalent endpoint) with parse_method='pipeline', 'vlm', 'hybrid', 'TXT', or omitting an unrecognized value; old clients that used backend names as parse_method.

Common situations: Version migration: pre-2.x mineru API accepted method names that are now backends; scripts built against older /docs swagger; language confusion between 'backend' and 'parse_method' parameters.

Related errors


AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14). Data as JSON: /api/errors/85fa8cecda66e9f1. Report an issue: GitHub.