IndexError in accumulate_event during Responses API streaming
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.6k
- Forks
- 5.7k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 96
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).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading openai/lib/streaming/responses/_responses.py, especially accumulate_event at line 344 and its callers handle_event and stream. Reproduce the intermittent failure with AsyncOpenAI().responses.stream() using the Responses API context described, then verify that streaming and resuming with starting_after complete without an IndexError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100