{"record":{"id":"fd2e5fa192dbcb07","repo":"BerriAI/litellm","slug":"error-message-or-raw-response-text","errorCode":null,"errorMessage":"error_message or raw_response.text","messagePattern":"error_message or raw_response\\.text","errorType":"exception","errorClass":"OpenAIError","httpStatus":null,"severity":"error","filePath":"litellm/llms/chatgpt/responses/transformation.py","lineNumber":127,"sourceCode":"        raw_response: Any,\n        logging_obj: Any,\n    ):\n        body_text: Final = raw_response.text or \"\"\n        if not self._should_parse_as_sse(raw_response=raw_response, body_text=body_text):\n            return super().transform_response_api_response(\n                model=model,\n                raw_response=raw_response,\n                logging_obj=logging_obj,\n            )\n\n        logging_obj.post_call(\n            original_response=raw_response.text,\n            additional_args={\"complete_input_dict\": {}},\n        )\n\n        completed_response, error_message = self._extract_completed_response_from_sse(body_text=body_text)\n        if completed_response is None:\n            raise OpenAIError(\n                message=error_message or raw_response.text,\n                status_code=raw_response.status_code,\n            )\n\n        self._attach_response_headers(completed_response=completed_response, raw_response=raw_response)\n        return completed_response\n\n    def _should_parse_as_sse(self, raw_response: Any, body_text: str) -> bool:\n        content_type: Final = (raw_response.headers or {}).get(\"content-type\", \"\")\n        if \"text/event-stream\" in content_type.lower():\n            return True\n        trimmed_body: Final = body_text.lstrip()\n        return bool(\n            trimmed_body.startswith(\"event:\")\n            or trimmed_body.startswith(\"data:\")\n            or \"\\nevent:\" in body_text\n            or \"\\ndata:\" in body_text\n        )","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/chatgpt/responses/transformation.py#L109-L145","documentation":"Raised as `OpenAIError` on the ChatGPT Responses path when the SSE body could not be parsed into a completed response. `error_message` comes from the SSE extraction helper; if it is empty the raw response text is used instead, and the HTTP status of the original response is preserved. It means the streaming payload was malformed, contained an error event, or the endpoint returned an error page rather than events.","triggerScenarios":"Calling the chatgpt provider's responses endpoint and receiving a non-SSE error body (HTML block page, JSON error) that reaches the SSE parser, or a stream that ends before a terminal/completed event arrives (proxy truncation, connection cut mid-stream).","commonSituations":"Corporate proxies buffering or truncating event-streams; model/parameter combos the ChatGPT backend rejects mid-stream; account/session errors surfacing as error events; outdated litellm SSE parsing against a changed event schema.","solutions":["Read the message body — it contains either the SSE error text or the raw response, which names the real problem.","Retry once; truncated streams are often transient network artifacts.","Disable stream buffering on intermediate proxies (`X-Accel-Buffering: no`, disable response buffering) for `text/event-stream`.","Upgrade litellm if the ChatGPT responses event schema changed; if persistent, capture the raw body and report it."],"exampleFix":"// before\nresp = litellm.responses(model=\"chatgpt/gpt-4o\", input=\"hi\", stream=True)\n\n// after (guard and inspect)\ntry:\n    resp = litellm.responses(model=\"chatgpt/gpt-4o\", input=\"hi\", stream=True)\nexcept litellm.llms.openai.common_utils.OpenAIError as e:\n    logger.error(\"responses failed status=%s body=%s\", e.status_code, e.message)\n    raise","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.responses(model=\"chatgpt/gpt-4o\", input=\"hi\", stream=True)\nexcept OpenAIError as e:\n    log.error(\"responses SSE parse failed status=%s body=%.500s\", e.status_code, e.message)\n    if e.status_code in (502, 503, 504):\n        backoff_and_retry_once()\n    else:\n        raise","preventionTips":["Disable proxy buffering for text/event-stream responses.","Log the embedded raw body on failure — it names the true cause.","Keep litellm current so SSE event parsing matches the schema."],"tags":["chatgpt","responses-api","sse","streaming","parsing"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}