{"record":{"id":"5e552c0ebf370ad9","repo":"BerriAI/litellm","slug":"invalid-json-in-request-body-e-ensure-the-requ","errorCode":null,"errorMessage":"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.","messagePattern":"Invalid JSON in request body: (.+?)\\. Ensure the request body is valid JSON with Content-Type: application/json, or use multipart/form-data for file uploads\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/ocr_endpoints/endpoints.py","lineNumber":157,"sourceCode":"        # The body may be empty because the auth middleware already parsed\n        # it as form data (e.g., _read_request_body called request.form()).\n        # Check if form data is available.\n        if getattr(request, \"_form\", None) is not None:\n            verbose_proxy_logger.debug(\n                \"OCR request body is empty but form data is available from middleware — processing as multipart form.\"\n            )\n            return await _parse_multipart_form(request)\n\n        raise ValueError(\n            \"Empty request body. For file uploads, use multipart/form-data content type \"\n            \"with a file field. When using curl with --form/-F, do NOT set the Content-Type \"\n            \"header manually.\"\n        )\n\n    try:\n        data: Final = orjson.loads(body)\n    except orjson.JSONDecodeError as e:\n        raise ValueError(\n            f\"Invalid JSON in request body: {e}. \"\n            \"Ensure the request body is valid JSON with Content-Type: application/json, \"\n            \"or use multipart/form-data for file uploads.\"\n        )\n\n    # Security: reject type=\"file\" documents received via JSON.\n    # The \"file\" document type is designed for local SDK usage where the\n    # caller and the process share a filesystem.  In the proxy context the\n    # caller is remote, so allowing a file-path string would let an\n    # authenticated user read arbitrary files from the server's filesystem.\n    # File uploads must go through multipart/form-data instead.\n    doc: Final = data.get(\"document\") if isinstance(data, dict) else None\n    if isinstance(doc, dict) and doc.get(\"type\") == \"file\":\n        raise ValueError(\n            \"document type 'file' is not supported through the JSON API. \"\n            \"To upload a local file, use multipart/form-data with a 'file' field. \"\n            \"For JSON requests, use 'document_url' or 'image_url' document types.\"\n        )","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/ocr_endpoints/endpoints.py#L139-L175","documentation":"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.","triggerScenarios":"Thrown at litellm/proxy/ocr_endpoints/endpoints.py:157 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Send valid JSON with Content-Type: application/json, or use multipart/form-data for file uploads."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}