openai/openai-python · error · RuntimeError
Expected to have received `response.created` before `{event.
Error message
Expected to have received `response.created` before `{event.type}` What it means
Raised by the internal accumulation state when a non-`response.created` event arrives before `response.created`. The Responses streaming accumulator builds its initial ParsedResponseSnapshot from `response.created`, so any other event appearing first leaves it with nothing to accumulate into.
Source
Thrown at src/openai/lib/streaming/responses/_responses.py:370
content = output.content[event.content_index]
assert content.type == "output_text"
content.text += event.delta
elif event.type == "response.function_call_arguments.delta":
output = snapshot.output[event.output_index]
if output.type == "function_call":
output.arguments += event.delta
elif event.type == "response.completed":
self._completed_response = parse_response(
text_format=self._text_format,
response=event.response,
input_tools=self._input_tools,
)
return snapshot
def _create_initial_response(self, event: RawResponseStreamEvent) -> ParsedResponseSnapshot:
if event.type != "response.created":
raise RuntimeError(f"Expected to have received `response.created` before `{event.type}`")
return construct_type_unchecked(type_=ParsedResponseSnapshot, value=event.response.to_dict())
View on GitHub (pinned to 9917c6e28e)
Solutions
- Fix the event source so `response.created` is the first event of the stream.
- In tests, prepend a `response.created` event to your mock stream.
- If using a proxy, verify it forwards the initial SSE event unchanged.
Example fix
// before events = ["response.output_item.added", ...] // after events = ["response.created", "response.output_item.added", ..., "response.completed"]
Defensive patterns
Strategy: validation
Type guard
def starts_with_created(events: list[str]) -> bool:
return bool(events) and events[0] == "response.created" Try / catch
try:
stream = client.responses.stream(...)
except RuntimeError as e:
if "response.created" in str(e):
raise ValueError("event source violates Responses streaming protocol") from e
raise Prevention
- Validate mock event sequences in tests before feeding them to the SDK.
- Never reorder or filter SSE events in custom proxies.
- Pin the Responses API protocol version your backend implements.
When it happens
Trigger: A stream whose first event is `response.in_progress`, `response.output_item.added`, or any delta event instead of `response.created`; typically from a custom/proxy server or a reordered mock event sequence.
Common situations: Hand-written SSE fixtures in tests that omit response.created; middleware or proxies dropping the first event; using a non-OpenAI backend that implements a different event order.
Related errors
- Didn't receive a `response.completed` event.
- Cannot provide both response_id/starting_after can't be prov
- input must be provided when creating a new response
- WebSocket connection closed with unsent messages
- Missing stream class
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/5773082ce2f16a33.
Report an issue: GitHub.