Confirm this is an issue with the Python library and not an underlying OpenAI API
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
Confirm this is an issue with the Python library and not an underlying OpenAI API
Describe the bug
client.responses.stream(...)raisesTypeError: 'NoneType' object is not iterablewhen the server emits aresponse.completedevent in whichresponse.outputisNone. The SDK's accumulator unconditionally callsparse_response()on the completed event, andparse_responsedoesfor output in response.output:without toleratingNone.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 precedingresponse.output_item.doneevents, and the finalresponse.completedevent carriesoutput=None. The officialapi.openai.com/v1/responsesendpoint populatesresponse.outputin 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):
Traceback:
Code snippets
The fix is a one-line defensive change in
openai/lib/_parsing/_responses.py:I've applied this locally and the stream completes cleanly; the actual output is still recoverable from the prior
response.output_item.doneevents (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