Skip to content

[BUG] Streaming Error Event Format Mismatch #881

Closed as not planned
Closed as not planned

Description

@TheGrayFrost

Describe the bug

Title

Responses API streaming error event has nested structure not matching documentation

Description

The streaming error event from the Responses API returns a nested JSON structure that differs from the documented format, causing SDK deserialization to fail.

Documented Format

Per the API reference at:
https://platform.openai.com/docs/api-reference/responses-streaming/error

{
  "type": "error",
  "code": "ERR_SOMETHING",
  "message": "Something went wrong",
  "param": null,
  "sequence_number": 1
}

Actual Format Received

{
  "type": "error",
  "sequence_number": 2,
  "error": {
    "type": "too_many_requests",
    "code": "too_many_requests",
    "message": "Too Many Requests",
    "param": null
  }
}

Problem

The SDK deserializer in StreamingResponseErrorUpdate.Serialization.cs expects code, message, and param at the root level. With the nested error object, these properties are not found and remain null.

Impact

  • StreamingResponseErrorUpdate.Code is null
  • StreamingResponseErrorUpdate.Message is null
  • StreamingResponseErrorUpdate.Param is null
  • Error details are inaccessible to applications

Steps to Reproduce

  1. Call Responses API with stream: true
  2. Trigger a rate limit (429) error
  3. Observe the streamed error event format

Suggested Fix

Update the API to return the documented flat structure, or update documentation to reflect the nested error object format.

OS

All (We hit on Windows and Linux)

.NET version

All (We hit on .NET 9)

Library version

All (We hit on 2.5.0)

Activity

  1. ShivangiReja commented on Dec 20, 2025

    @ShivangiReja
    Contributor

    Hi @TheGrayFrost, thanks for reaching out. I tried reproducing this and you’re right. The API documentation and the REST API spec currently describes the error event in this flat format:

    {
      "type": "error",
      "code": "ERR_SOMETHING",
      "message": "Something went wrong",
      "param": "input",
      "sequence_number": 1
    }

    However, the service is returning a nested format like this:

    {
      "type": "error",
      "sequence_number": 2,
      "error": {
        "type": "invalid_request_error",
        "code": "context_length_exceeded",
        "message": "Your input exceeds the context window of this model. Please adjust your input and try again.",
        "param": "input"
      }
    }

    Because StreamingResponseErrorUpdate.Serialization.cs expects code, message, and param at the root level, deserialization fails and these properties remain null.

    In this case, it appears that the OpenAI service is not honoring its public contract and is intermittently returning an incorrect error response. This behavior is on the service-side, the client library has no insight nor influence over it. Unfortunately, OpenAI does not offer service support from this repository. The most reliable and direct way to get support is by reaching out to the OpenAI Support Team. You can either email [email protected] or start a new chat session via the Help Center. The OpenAI support team is available 24/7 and is equipped to assist with the full range of requests.

    In the meantime, you can access the fields via the Patch property.

    Example:

    var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
    ResponsesClient client = new(model: "gpt-5", apiKey: apiKey);
    
    int repeats = 2000000;
    var sb = new StringBuilder(capacity: repeats * 2);
    for (int i = 0; i < repeats; i++) sb.Append("x ");
    string oversizedPrompt = sb.ToString();
    
    CollectionResult<StreamingResponseUpdate> responseUpdates = client.CreateResponseStreaming(oversizedPrompt);
    
    foreach (StreamingResponseUpdate update in responseUpdates)
    {
        if (update is StreamingResponseErrorUpdate err)
        {
            var type = err.Patch.GetString("$.error.type"u8);
            var code = err.Patch.GetString("$.error.code"u8);
            var message = err.Patch.GetString("$.error.message"u8);
            var param = err.Patch.GetString("$.error.param"u8);
    
            Console.WriteLine($"[STREAM ERROR] type={type} code={code} param={param} message={message}");
        }
    }
  2. added
    blocked: upstreamThis issue is blocked on an upstream change, such as to the REST API spec or generator.
    on Dec 20, 2025
  3. stephentoub commented on Dec 20, 2025

    @stephentoub
    Contributor
  4. added
    bugCategory: Something isn't working and appears to be a defect in the client library.
    area: serviceThis issue is an inquiry about a bug in the OpenAI service or requesting a new service feature.
    and removed
    blocked: upstreamThis issue is blocked on an upstream change, such as to the REST API spec or generator.
    on Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: serviceThis issue is an inquiry about a bug in the OpenAI service or requesting a new service feature.bugCategory: Something isn't working and appears to be a defect in the client library.needs-triageWorkflow: This is a new issue that needs to be triaged.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions