Skip to content

Responses API error handling reads error.message, but spec says message is top-level #2487

@whichxjy

Description

@whichxjy

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.

SDK code (current behavior):

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"].

To Reproduce

Code snippets

OS

Python version

Library version

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsdk

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions