BerriAI/litellm · error · ValueError

Multipart OCR request must include a 'file' field with the…

Error message

Multipart OCR request must include a 'file' field with the document to process

What it means

ValueError raised while parsing an OCR proxy request as multipart/form-data: the form parsed successfully but contains no 'file' field, so there is no document to OCR. Fires when the client uploads without naming the file part 'file'.

Solutions

  1. Include a 'file' field with the document in the multipart/form-data request.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/ocr_endpoints/endpoints.py:68 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/1bc9fb37bf6fded6. Report an issue: GitHub.

Appendix: source

Thrown at litellm/proxy/ocr_endpoints/endpoints.py:68

    Returns:
        A dict with 'document', 'model', and any other OCR params.
    """
    try:
        form: Final = await request.form()
    except Exception as e:
        raise ValueError(
            f"Failed to parse multipart form data: {e}. "
            "When using curl with --form/-F, do NOT set the Content-Type header "
            "manually — curl will set it automatically with the required boundary."
        )

    uploaded_file = form.get("file")
    # request.form() may return either a FastAPI or Starlette UploadFile
    # depending on middleware; check both via isinstance (FastAPI's UploadFile
    # is a subclass of Starlette's) and fall back to duck-type check.
    if uploaded_file is None or (not isinstance(uploaded_file, UploadFile) and not hasattr(uploaded_file, "read")):
        raise ValueError("Multipart OCR request must include a 'file' field with the document to process")

    uploaded_file = cast(UploadFile, uploaded_file)

    # Seek to start in case the file was already partially read by middleware
    await uploaded_file.seek(0)
    file_content: Final = await uploaded_file.read()
    if not file_content:
        raise ValueError("Uploaded file is empty")

    document: Final = _build_document_from_upload(
        file_content=file_content,
        filename=uploaded_file.filename,
        content_type=uploaded_file.content_type,
    )

    data: Final[dict[str, Any]] = {"document": document}

    for field_name, field_value in form.items():

View on GitHub (pinned to 77b7c6c40c)