Skip to content

Responses stream accumulator crashes when response.output_item.added has item=None #3125

Description

@dddsdsdszzzzz

Bug description

A response.output_item.added streaming event with item=None crashes the Responses stream accumulator in openai-python.

This is not specific to one app. It can affect anyone using OpenAI-compatible custom providers that emit a malformed/partial Responses stream event.

Current behavior

In openai/lib/streaming/responses/_responses.py, the accumulator assumes event.item is always present for response.output_item.added and dereferences event.item.type.

When a provider sends response.output_item.added with item: null, the client crashes with:

AttributeError: 'NoneType' object has no attribute 'type'

That exception happens inside the SDK stream accumulator before application-level code can recover.

Why this matters

Even if the upstream OpenAI API never emits this shape, the Python SDK is widely used against OpenAI-compatible providers. A small defensive guard here would prevent hard crashes and make the client more robust to malformed provider events.

Suggested fix

In the response.output_item.added handler, guard against a missing item before accessing .type.

Conceptually:

item = getattr(event, "item", None)
if item is None:
    return snapshot

Environment

  • Library: openai-python
  • Affected area: Responses streaming accumulator (_responses.py)
  • Trigger source: custom OpenAI-compatible provider returning response.output_item.added with item=None

Reproduction notes

I hit this in production against a custom provider endpoint implementing the OpenAI Responses API shape. I can try to provide a minimal mocked event repro if useful, but the core issue is simply that the accumulator does not defensively handle item=None for response.output_item.added.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions