BerriAI/litellm · error · ValueError
Failed to parse multipart form data: {e}. When using curl wi
Error message
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. What it means
Error "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." thrown in BerriAI/litellm.
Source
Thrown at litellm/proxy/ocr_endpoints/endpoints.py:57
"mime_type": mime_type or "application/octet-stream",
}
)
async def _parse_multipart_form(request: Request) -> dict[str, Any]:
"""
Extract OCR data from a multipart form request.
Uses the cached form if already parsed by auth middleware,
otherwise parses the form from the request.
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:View on GitHub (pinned to 77b7c6c40c)
Solutions
- When using curl with --form/-F, do not set the Content-Type header manually; let curl set it with the boundary.
When it happens
Trigger: Thrown at litellm/proxy/ocr_endpoints/endpoints.py:57 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/34ceb777c652fd3e.
Report an issue: GitHub.