-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Bug Report
Description
IndexError: list index out of range occurs inside the OpenAI SDK during streaming of Responses API events. The error originates in openai/lib/streaming/responses/_responses.py line 344 in accumulate_event, called from handle_event (line 248) and __stream__ (line 156).
This is not caused by application code — it happens internally within the SDK's stream accumulator.
Stack Trace
File "/app/.venv/lib/python3.13/site-packages/openai/lib/streaming/responses/_responses.py", line 151, in __aiter__
File "/app/.venv/lib/python3.13/site-packages/openai/lib/streaming/responses/_responses.py", line 156, in __stream__
File "/app/.venv/lib/python3.13/site-packages/openai/lib/streaming/responses/_responses.py", line 248, in handle_event
File "/app/.venv/lib/python3.13/site-packages/openai/lib/streaming/responses/_responses.py", line 344, in accumulate_event
IndexError: list index out of range
Reproduction Context
- SDK version:
openai==2.16.0 - Python version: 3.13
- API: Responses API with streaming (
stream=True) - Model:
gpt-5-nano - Features used:
tools=[{"type": "web_search"}], structured output withtext_format(Pydantic model) - Streaming method:
AsyncOpenAI().responses.stream()and resume viaresponses.stream()withstarting_after
Code Pattern
async with client.responses.stream(...) as stream:
async for event in stream: # IndexError thrown here intermittently
...The error occurs intermittently — most streams complete fine, but occasionally the accumulator hits an index that doesn't exist in its internal list.
Workaround
Wrapping the stream iteration in a try/except IndexError to catch and log the error, since the stream has typically delivered the important data by the time this occurs.
Notes
A similar class of bug exists in the Assistants API streaming path (_assistants.py in accumulate_event) — see #1736 and #1882. This issue is for the newer Responses API streaming path (responses/_responses.py).