BerriAI/litellm · error · ValueError
Invalid JSON in request body: {e}. Ensure the request body i
Error message
Invalid JSON in request body: {e}. Ensure the request body is valid JSON with Content-Type: application/json, or use multipart/form-data for file uploads. What it means
ValueError raised when the OCR request body cannot be parsed: the body is not valid JSON (parse exception embedded), and guidance is given to either send valid JSON with the right content type or switch to multipart/form-data for file uploads. Covers malformed JSON and wrong content-type usage.
Source
Thrown at litellm/proxy/ocr_endpoints/endpoints.py:157
# The body may be empty because the auth middleware already parsed
# it as form data (e.g., _read_request_body called request.form()).
# Check if form data is available.
if getattr(request, "_form", None) is not None:
verbose_proxy_logger.debug(
"OCR request body is empty but form data is available from middleware — processing as multipart form."
)
return await _parse_multipart_form(request)
raise ValueError(
"Empty request body. For file uploads, use multipart/form-data content type "
"with a file field. When using curl with --form/-F, do NOT set the Content-Type "
"header manually."
)
try:
data: Final = orjson.loads(body)
except orjson.JSONDecodeError as e:
raise ValueError(
f"Invalid JSON in request body: {e}. "
"Ensure the request body is valid JSON with Content-Type: application/json, "
"or use multipart/form-data for file uploads."
)
# Security: reject type="file" documents received via JSON.
# The "file" document type is designed for local SDK usage where the
# caller and the process share a filesystem. In the proxy context the
# caller is remote, so allowing a file-path string would let an
# authenticated user read arbitrary files from the server's filesystem.
# File uploads must go through multipart/form-data instead.
doc: Final = data.get("document") if isinstance(data, dict) else None
if isinstance(doc, dict) and doc.get("type") == "file":
raise ValueError(
"document type 'file' is not supported through the JSON API. "
"To upload a local file, use multipart/form-data with a 'file' field. "
"For JSON requests, use 'document_url' or 'image_url' document types."
)View on GitHub (pinned to 77b7c6c40c)
Solutions
- Send valid JSON with Content-Type: application/json, or use multipart/form-data for file uploads.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at litellm/proxy/ocr_endpoints/endpoints.py:157 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/5e552c0ebf370ad9.
Report an issue: GitHub.