{"record":{"id":"c8d1f3e332b06e11","repo":"openai/openai-python","slug":"an-error-occurred-during-streaming","errorCode":null,"errorMessage":"An error occurred during streaming","messagePattern":"An error occurred during streaming","errorType":"exception","errorClass":"APIError","httpStatus":null,"severity":"error","filePath":"src/openai/_streaming.py","lineNumber":79,"sourceCode":"\n        try:\n            for sse in iterator:\n                if sse.data.startswith(\"[DONE]\"):\n                    break\n\n                # we have to special case the Assistants `thread.` events since we won't have an \"event\" key in the data\n                if sse.event and sse.event.startswith(\"thread.\"):\n                    data = sse.json()\n\n                    if sse.event == \"error\" and is_mapping(data) and data.get(\"error\"):\n                        message = None\n                        error = data.get(\"error\")\n                        if is_mapping(error):\n                            message = error.get(\"message\")\n                        if not message or not isinstance(message, str):\n                            message = \"An error occurred during streaming\"\n\n                        raise APIError(\n                            message=message,\n                            request=self.response.request,\n                            body=data[\"error\"],\n                        )\n\n                    yield process_data(data={\"data\": data, \"event\": sse.event}, cast_to=cast_to, response=response)\n                else:\n                    data = sse.json()\n                    if is_mapping(data) and data.get(\"error\"):\n                        message = None\n                        error = data.get(\"error\")\n                        if is_mapping(error):\n                            message = error.get(\"message\")\n                        if not message or not isinstance(message, str):\n                            message = \"An error occurred during streaming\"\n\n                        raise APIError(\n                            message=message,","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_streaming.py#L61-L97","documentation":"While processing a server-sent-event stream, if an event payload contains an 'error' key whose message is missing or not a string, the SDK raises APIError with the generic message 'An error occurred during streaming'. It is the fallback message for malformed in-stream error payloads.","triggerScenarios":"An SSE stream from a Responses/Chat API yields a JSON event like {\"error\": {}} or {\"error\": \"non-mapping\"} where error.message is absent or not a string, during iteration of stream(...) or the stream created by a streaming request.","commonSituations":"Intermediate proxies or compatible-server implementations emitting non-standard error events; truncated or malformed stream payloads; API incidents that emit unusual error schemas.","solutions":["Wrap stream iteration in try/except openai.APIError and inspect response/request context to learn more","Check the OpenAI status page or your proxy logs for the underlying upstream error","If running a compatible server, emit errors as {\"error\": {\"message\": \"...\"}} so the real message surfaces"],"exampleFix":"# before\nfor event in stream:\n    handle(event)\n\n# after\ntry:\n    for event in stream:\n        handle(event)\nexcept openai.APIError as e:\n    log.error(\"stream failed: %s\", e)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"import openai\ntry:\n    for event in stream:\n        handle(event)\nexcept openai.APIError as e:\n    log.error(\"stream error: %s (request=%s)\", e.message, e.request)","preventionTips":["Always wrap SSE iteration in APIError handling","Log raw frames in debug mode when diagnosing malformed error events"],"tags":["streaming","sse","api-error","error-payload"],"backgroundTag":"sse-stream-error-event","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}