-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Open
Labels
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
In the Responses API event handling logic, the SDK reads the error message from error.message. However, according to the official documentation, the message field is at the top level of the error object, not nested inside another error field.
if sse.event == "error" and is_mapping(data) and data.get("error"):
message = None
error = data.get("error")
if is_mapping(error):
message = error.get("message")
if not message or not isinstance(message, str):
message = "An error occurred during streaming"
raise APIError(
message=message,
request=self.response.request,
body=data["error"],
)
Official API response example:
{
"type": "error",
"code": "ERR_SOMETHING",
"message": "Something went wrong",
"param": null,
"sequence_number": 1
}
Proposed fix: Change the error handling logic to read data["message"]
(the top-level field) and data["error"]["message"]
(for backward compatibility) instead of only data["error"]["message"]
.