Describe the bug
parse_response in src/openai/lib/_parsing/_responses.py iterates response.output without guarding against None:
# src/openai/lib/_parsing/_responses.py
def parse_response(...):
output_list: List[...] = []
for output in response.output: # <-- TypeError if response.output is None
When a streaming Responses API call accumulates a final Response whose output is None, the stream state machine crashes with an unhelpful TypeError: 'NoneType' object is not iterable deep inside the SDK — it surfaces from accumulate_event, not as a catchable API error, so it takes down the whole stream rather than yielding an empty/degraded result.
This is still present on main as of today (also reproduces on 2.32.0).
To Reproduce
Using the streaming Responses API where the completed response has output=None (observed with a backend that returns a reasoning-only / incomplete response with a null output array):
with client.responses.stream(model=..., input=[...]) as stream:
for event in stream: # raises during event accumulation
...
final = stream.get_final_response()
Traceback:
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
Expected behavior
parse_response should defensively handle response.output is None and treat it as an empty output list, so a null/absent output yields a ParsedResponse with no output items instead of crashing the stream. output being null can occur for incomplete/failed/reasoning-only responses and via proxy/aggregator backends; the SDK hard-crashing here is difficult to handle downstream because the error originates inside the streaming accumulator.
Suggested fix
One line:
- for output in response.output:
+ for output in (response.output or []):
Happy to open a PR if that's the preferred path.
Environment
- openai-python: 2.32.0 (unguarded loop confirmed still on
main)
- Python: 3.11
- API surface:
responses.stream(...) (streaming Responses API)
Describe the bug
parse_responseinsrc/openai/lib/_parsing/_responses.pyiteratesresponse.outputwithout guarding againstNone:When a streaming Responses API call accumulates a final
ResponsewhoseoutputisNone, the stream state machine crashes with an unhelpfulTypeError: 'NoneType' object is not iterabledeep inside the SDK — it surfaces fromaccumulate_event, not as a catchable API error, so it takes down the whole stream rather than yielding an empty/degraded result.This is still present on
mainas of today (also reproduces on2.32.0).To Reproduce
Using the streaming Responses API where the completed response has
output=None(observed with a backend that returns a reasoning-only / incomplete response with a nulloutputarray):Traceback:
Expected behavior
parse_responseshould defensively handleresponse.output is Noneand treat it as an empty output list, so a null/absentoutputyields aParsedResponsewith no output items instead of crashing the stream.outputbeing null can occur for incomplete/failed/reasoning-only responses and via proxy/aggregator backends; the SDK hard-crashing here is difficult to handle downstream because the error originates inside the streaming accumulator.Suggested fix
One line:
Happy to open a PR if that's the preferred path.
Environment
main)responses.stream(...)(streaming Responses API)