From 120339c0aeb6c4a4e5d02c544d617eb48059740c Mon Sep 17 00:00:00 2001 From: Rishab Motgi Date: Wed, 20 May 2026 13:04:34 -0700 Subject: [PATCH] remove unreachable error block in thread. event streaming path 'sse.event == "error"' can never be true inside the 'startswith("thread.")' branch, so the APIError raise block was dead code. The else branch already handles error events correctly. Remove the dead block from both sync and async paths. Fixes #2796 --- src/openai/_streaming.py | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/openai/_streaming.py b/src/openai/_streaming.py index 45c13cc11d..09aaac7ca0 100644 --- a/src/openai/_streaming.py +++ b/src/openai/_streaming.py @@ -66,21 +66,6 @@ def __stream__(self) -> Iterator[_T]: # we have to special case the Assistants `thread.` events since we won't have an "event" key in the data if sse.event and sse.event.startswith("thread."): data = sse.json() - - if sse.event == "error" and is_mapping(data) and data.get("error"): - message = None - error = data.get("error") - if is_mapping(error): - message = error.get("message") - if not message or not isinstance(message, str): - message = "An error occurred during streaming" - - raise APIError( - message=message, - request=self.response.request, - body=data["error"], - ) - yield process_data(data={"data": data, "event": sse.event}, cast_to=cast_to, response=response) else: data = sse.json() @@ -176,21 +161,6 @@ async def __stream__(self) -> AsyncIterator[_T]: # we have to special case the Assistants `thread.` events since we won't have an "event" key in the data if sse.event and sse.event.startswith("thread."): data = sse.json() - - if sse.event == "error" and is_mapping(data) and data.get("error"): - message = None - error = data.get("error") - if is_mapping(error): - message = error.get("message") - if not message or not isinstance(message, str): - message = "An error occurred during streaming" - - raise APIError( - message=message, - request=self.response.request, - body=data["error"], - ) - yield process_data(data={"data": data, "event": sse.event}, cast_to=cast_to, response=response) else: data = sse.json()