From 2a90721e76e036ca0627155494e304f8bd111384 Mon Sep 17 00:00:00 2001 From: sharziki Date: Thu, 14 May 2026 20:56:54 -0400 Subject: [PATCH] fix: guard against item=None in response.output_item.added accumulator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Responses stream accumulator assumed event.item is always present for response.output_item.added events and immediately accessed event.item.type. When an OpenAI-compatible provider sends this event with item=None, the client crashes with: AttributeError: 'NoneType' object has no attribute 'type' Add a defensive None check so the accumulator gracefully skips malformed events instead of crashing. Closes #3125 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/openai/lib/streaming/responses/_responses.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/openai/lib/streaming/responses/_responses.py b/src/openai/lib/streaming/responses/_responses.py index 6975a9260d..2c803889c4 100644 --- a/src/openai/lib/streaming/responses/_responses.py +++ b/src/openai/lib/streaming/responses/_responses.py @@ -328,7 +328,9 @@ def accumulate_event(self, event: RawResponseStreamEvent) -> ParsedResponseSnaps return self._create_initial_response(event) if event.type == "response.output_item.added": - if event.item.type == "function_call": + if event.item is None: + pass + elif event.item.type == "function_call": snapshot.output.append( construct_type_unchecked( type_=cast(Any, ParsedResponseFunctionToolCall), value=event.item.to_dict()