Skip to content

responses.stream crashes with TypeError: 'NoneType' object is not iterable when server emits response.completed with output=None #3312

@fauzandotme

Description

@fauzandotme

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

client.responses.stream(...) raises TypeError: 'NoneType' object is not iterable when the server emits a response.completed event in which response.output is None. The SDK's accumulator unconditionally calls parse_response() on the completed event, and parse_response does for output in response.output: without tolerating None.

I hit this against https://chatgpt.com/backend-api/codex/responses (the ChatGPT Codex backend used by Codex CLI / IDE integrations and OAuth-token clients). On that backend, the real output items are delivered as preceding response.output_item.done events, and the final response.completed event carries output=None. The official api.openai.com/v1/responses endpoint populates response.output in the completed event, so this only reproduces against the Codex backend.

To Reproduce

Minimal reproducer (requires a ChatGPT Codex OAuth access token; the same client config Codex CLI uses):

from openai import OpenAI

client = OpenAI(
    api_key="<codex-oauth-access-token>",
    base_url="https://chatgpt.com/backend-api/codex",
)

with client.responses.stream(
    model="gpt-5.5",
    input=[{"role": "user", "content": "hello"}],
    instructions="You are helpful.",
    store=True,
    reasoning={"effort": "medium", "summary": "auto"},
    include=[],
    tool_choice="auto",
    parallel_tool_calls=True,
    prompt_cache_key="repro",
) as stream:
    for _ in stream:
        pass
    stream.get_final_response()

Traceback:

File ".../openai/lib/streaming/responses/_responses.py", line 49, in __iter__
  for item in self._iterator:
File ".../openai/lib/streaming/responses/_responses.py", line 57, in __stream__
  events_to_fire = self._state.handle_event(sse_event)
File ".../openai/lib/streaming/responses/_responses.py", line 248, in handle_event
  self.__current_snapshot = snapshot = self.accumulate_event(event)
File ".../openai/lib/streaming/responses/_responses.py", line 360, in accumulate_event
  self._completed_response = parse_response(
File ".../openai/lib/_parsing/_responses.py", line 61, in parse_response
  for output in response.output:
TypeError: 'NoneType' object is not iterable

Code snippets

The fix is a one-line defensive change in openai/lib/_parsing/_responses.py:

- for output in response.output:
+ for output in (response.output or []):

I've applied this locally and the stream completes cleanly; the actual output is still recoverable from the prior response.output_item.done events (which is how the Codex backend delivers it in the first place).

OS

macOS 15 (Darwin 25.4.0)

Python version

Python 3.11

Library version

openai==2.24.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions