{"record":{"id":"8d60a28e6e6c1442","repo":"BerriAI/litellm","slug":"original-response-received-raw-response-text","errorCode":null,"errorMessage":"Original Response received: {raw_response.text}","messagePattern":"Original Response received: (.+?)","errorType":"http","errorClass":"HuggingFaceError","httpStatus":null,"severity":"error","filePath":"litellm/llms/huggingface/embedding/transformation.py","lineNumber":505,"sourceCode":"                model=model,\n                data=request_data,\n                api_key=api_key,\n            )\n        else:\n            ## LOGGING\n            logging_obj.post_call(\n                input=request_data,\n                api_key=api_key,\n                original_response=raw_response.text,\n                additional_args={\"complete_input_dict\": request_data},\n            )\n            ## RESPONSE OBJECT\n            try:\n                completion_response = raw_response.json()\n                if isinstance(completion_response, dict):\n                    completion_response = [completion_response]\n            except Exception:\n                raise HuggingFaceError(\n                    message=f\"Original Response received: {raw_response.text}\",\n                    status_code=raw_response.status_code,\n                )\n\n        if isinstance(completion_response, dict) and \"error\" in completion_response:\n            raise HuggingFaceError(\n                message=completion_response[\"error\"],\n                status_code=raw_response.status_code,\n            )\n        return self.convert_to_model_response_object(\n            completion_response=completion_response,\n            model_response=model_response,\n            task=task if task is not None and task in hf_task_list else None,\n            optional_params=optional_params,\n            encoding=encoding,\n            messages=messages,\n            model=model,\n        )","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/huggingface/embedding/transformation.py#L487-L523","documentation":"Raised when raw_response.json() throws — the HuggingFace completion endpoint returned a body that is not valid JSON (commonly an HTML error page, plain-text 502/503 from a proxy, or an empty body). The full raw body is embedded in the message so you can see what actually came back.","triggerScenarios":"HF inference endpoint behind a gateway returning HTML 502/504, a Cloudflare block page, an empty 500 response, or a mis-typed api_base that hits a non-JSON route.","commonSituations":"Self-hosted endpoints where the URL path is wrong (hits the UI page), transient infra errors, or corporate proxies replacing bodies with HTML.","solutions":["Read the embedded raw_response.text — HTML titles like '502 Bad Gateway' reveal the true source.","Fix api_base to point at the inference route (e.g. ends with the model path, not the web UI).","Retry with backoff for transient gateway errors.","Verify the endpoint with curl -v to confirm it serves JSON."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.completion(...)\nexcept litellm.llms.huggingface.common_utils.HuggingFaceError as e:\n    if '<html' in str(e).lower() or 'bad gateway' in str(e).lower():\n        logger.warning('gateway error from HF endpoint; retrying later')\n        raise TransientUpstreamError(str(e)) from e\n    raise","preventionTips":["Run endpoints behind health checks so gateways stop serving HTML error pages","Log the raw body (already in the message) to a dedicated channel for diagnosis"],"tags":["huggingface","completion","response-format","gateway","json"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}