From 683689d60cb5fe545135e10bdb64773cff7fce54 Mon Sep 17 00:00:00 2001 From: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com> Date: Thu, 5 Feb 2026 20:33:25 +0530 Subject: [PATCH] fix(streaming): remove unreachable sse.event == error check The `sse.event == "error"` condition was inside a block that requires `sse.event.startswith("thread.")`. Since "error" does not start with "thread.", this check was always False and unreachable. Changed from: if sse.event == "error" and is_mapping(data) and data.get("error"): To: if is_mapping(data) and data.get("error"): This allows error detection for thread.* events by checking the data payload instead of the event name, consistent with how errors are handled in the else branch for non-thread events. Fixes both sync (line 67) and async (line 170) versions. Fixes #2796 --- src/openai/_streaming.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openai/_streaming.py b/src/openai/_streaming.py index 61a742668a..a7cde6e9c9 100644 --- a/src/openai/_streaming.py +++ b/src/openai/_streaming.py @@ -64,7 +64,7 @@ def __stream__(self) -> Iterator[_T]: if sse.event and sse.event.startswith("thread."): data = sse.json() - if sse.event == "error" and is_mapping(data) and data.get("error"): + if is_mapping(data) and data.get("error"): message = None error = data.get("error") if is_mapping(error): @@ -167,7 +167,7 @@ async def __stream__(self) -> AsyncIterator[_T]: if sse.event and sse.event.startswith("thread."): data = sse.json() - if sse.event == "error" and is_mapping(data) and data.get("error"): + if is_mapping(data) and data.get("error"): message = None error = data.get("error") if is_mapping(error):