BerriAI/litellm · error · ValueError

Invalid document type: {doc_type}. Must be 'document_url', '

Error message

Invalid document type: {doc_type}. Must be 'document_url', 'image_url', or 'file'

What it means

Raised while preparing an OCR request when the `document` dict's 'type' field is not one of the three recognized kinds ('document_url', 'image_url', 'file'). The preceding check already guarantees document is a dict, so this error specifically means the type discriminator is missing or misspelled — e.g. a caller sent 'url' instead of 'document_url'.

Source

Thrown at litellm/ocr/main.py:88

    timeout: float | httpx.Timeout | None,
    custom_llm_provider: str | None,
    extra_headers: dict[str, object] | None,
    kwargs: dict[str, object],
) -> _PreparedOCRRequest:
    litellm_logging_obj: Final = cast(LiteLLMLoggingObj, kwargs.pop("litellm_logging_obj"))
    litellm_call_id: Final = cast(str | None, kwargs.get("litellm_call_id", None))

    if not isinstance(document, dict):
        raise ValueError(f"document must be a dict with 'type' and URL/file field, got {type(document)}")

    doc_type = document.get("type")

    if doc_type == "file":
        document = convert_file_document_to_url_document(document)
        doc_type = document.get("type")

    if doc_type not in ["document_url", "image_url"]:
        raise ValueError(f"Invalid document type: {doc_type}. Must be 'document_url', 'image_url', or 'file'")

    caller_supplied_api_base: Final = api_base is not None

    (
        model,
        custom_llm_provider,
        dynamic_api_key,
        dynamic_api_base,
    ) = litellm.get_llm_provider(
        model=model,
        custom_llm_provider=custom_llm_provider,
        api_base=api_base,
        api_key=api_key,
    )

    suppress_dynamic_api_base: Final = (
        not caller_supplied_api_base
        and custom_llm_provider == "azure_ai"

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Use one of the supported document types: 'document_url', 'image_url', or 'file'.
  2. Fix the 'type' value in the document dict to one of the supported literals.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/ocr/main.py:88 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/11b95b55f2596404. Report an issue: GitHub.