Closed
Description
Describe the bug
When streaming an agent response using the completions API with an Azure OpenAI endpoint, prompt annotations are returned from the model where the choices propery is []
. The following code does not adequately handle a choices property that exists, but contains no elements:
if (!chunk.choices || !chunk.choices[0].delta)
continue;
This results in a Cannot read properties of undefined (reading 'delta')
error.
Debug information
- Agents SDK version: (e.g.
v0.0.7
) - Runtime environment (e.g.
Node.js 22.16.0
)
Repro steps
Use an Azure OpenAI endpoint with any prompt and the following set:
setOpenAIAPI('chat_completions');
const stream = await runner.run(agent, messages, {
stream: true,
});
Expected behavior
At a minimum, the prompt annotations should be ignored and the streamed chat completion should resume.