diff --git a/api/chat/_stream.py b/api/chat/_stream.py index dcb7f52ab..921e8b2c2 100644 --- a/api/chat/_stream.py +++ b/api/chat/_stream.py @@ -165,13 +165,21 @@ async def respond_stream(self, prompt: str) -> AsyncIterator[str]: ) async for chunk in response: + # Responses API event shape + if getattr(chunk, "type", "") == "response.output_text.delta": + delta = getattr(chunk, "delta", None) + if delta: + yield delta + continue + + # Chat Completions chunk shape + choices = getattr(chunk, "choices", None) if ( - chunk.choices - and chunk.choices[0].delta is not None - and chunk.choices[0].delta.content is not None + choices + and choices[0].delta is not None + and choices[0].delta.content is not None ): - yield chunk.choices[0].delta.content - + yield choices[0].delta.content class OpenAIChatStreamer(_OpenAICompatStreamer): provider = "openai"