{"record":{"id":"0e7f0a0ccbf264b7","repo":"BerriAI/litellm","slug":"unable-to-get-json-response-e-original-respon-0e7f0a","errorCode":null,"errorMessage":"Unable to get json response - {e}, Original Response: {raw_response.text}","messagePattern":"Unable to get json response - (.+?), Original Response: (.+?)","errorType":"exception","errorClass":"OpenAIError","httpStatus":null,"severity":"error","filePath":"litellm/llms/openai/chat/gpt_transformation.py","lineNumber":620,"sourceCode":"\n        Returns:\n            dict: The transformed response.\n        \"\"\"\n\n        ## LOGGING\n        logging_obj.post_call(\n            input=messages,\n            api_key=api_key,\n            original_response=raw_response.text,\n            additional_args={\"complete_input_dict\": request_data},\n        )\n\n        ## RESPONSE OBJECT\n        try:\n            completion_response: Final = raw_response.json()\n        except Exception as e:\n            response_headers: Final = getattr(raw_response, \"headers\", None)\n            raise OpenAIError(\n                message=f\"Unable to get json response - {e}, Original Response: {raw_response.text}\",\n                status_code=raw_response.status_code,\n                headers=response_headers,\n            )\n        raw_response_headers: Final = dict(raw_response.headers)\n        final_response_obj: Final = convert_to_model_response_object(\n            response_object=completion_response,\n            model_response_object=model_response,\n            hidden_params={\"headers\": raw_response_headers},\n            _response_headers=raw_response_headers,\n        )\n\n        return cast(ModelResponse, final_response_obj)\n\n    def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException:\n        return OpenAIError(\n            status_code=status_code,\n            message=error_message,","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/openai/chat/gpt_transformation.py#L602-L638","documentation":"In the OpenAI chat transformation, `raw_response.json()` failure raises OpenAIError with the parse exception, the original response text, the status code, and the response headers. It means the OpenAI-compatible endpoint returned a non-JSON body.","triggerScenarios":"Any OpenAI-path completion where the server returns HTML or plain text: Cloudflare challenge pages, gateway 502 HTML, empty bodies, gzip corruption, or plain-text error strings from misconfigured OpenAI-compatible servers.","commonSituations":"Self-hosted OpenAI-compatible endpoints (vLLM, LocalAI, LM Studio) behind proxies; api_base typos hitting a website instead of an API; corporate SSL inspection returning an HTML block page; or a base URL missing the /v1 path so the server returns an HTML 404.","solutions":["Check the 'Original Response' in the message — it shows exactly what body came back (often an HTML page revealing the real problem).","Fix api_base to point at the correct API root (usually must include /v1, e.g. http://host:8000/v1).","Bypass or configure proxies/SSL inspection that inject HTML responses.","Verify the server is actually an OpenAI-compatible API with curl /v1/models."],"exampleFix":"# before\nlitellm.completion(model=\"openai/m\", api_base=\"http://localhost:8000\")  # missing /v1\n\n# after\nlitellm.completion(model=\"openai/m\", api_base=\"http://localhost:8000/v1\")","handlingStrategy":"validation","validationCode":"import httpx\nr = httpx.get(f\"{api_base}/models\", headers={\"Authorization\": f\"Bearer {api_key}\"})\nif \"json\" not in r.headers.get(\"content-type\", \"\"):\n    raise ValueError(f\"{api_base} is not returning JSON — check URL/proxy: {r.text[:200]}\")","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.completion(model=\"openai/m\", messages=msgs, api_base=base)\nexcept litellm.exceptions.OpenAIError as e:\n    if \"Unable to get json response\" in str(e):\n        # body was not JSON: message embeds the original text\n        diagnose_non_json_body(str(e))","preventionTips":["Always include /v1 in api_base for OpenAI-compatible servers","Startup-probe api_base for JSON responses","Watch the 'Original Response' field — it names the real culprit (proxy page, 404 HTML, etc.)"],"tags":["openai","json","response-parsing","api-base","proxy"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}