{"record":{"id":"5773082ce2f16a33","repo":"openai/openai-python","slug":"expected-to-have-received-response-created-befor","errorCode":null,"errorMessage":"Expected to have received `response.created` before `{event.type}`","messagePattern":"Expected to have received `response\\.created` before `(.+?)`","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/openai/lib/streaming/responses/_responses.py","lineNumber":370,"sourceCode":"                content = output.content[event.content_index]\n                assert content.type == \"output_text\"\n                content.text += event.delta\n        elif event.type == \"response.function_call_arguments.delta\":\n            output = snapshot.output[event.output_index]\n            if output.type == \"function_call\":\n                output.arguments += event.delta\n        elif event.type == \"response.completed\":\n            self._completed_response = parse_response(\n                text_format=self._text_format,\n                response=event.response,\n                input_tools=self._input_tools,\n            )\n\n        return snapshot\n\n    def _create_initial_response(self, event: RawResponseStreamEvent) -> ParsedResponseSnapshot:\n        if event.type != \"response.created\":\n            raise RuntimeError(f\"Expected to have received `response.created` before `{event.type}`\")\n\n        return construct_type_unchecked(type_=ParsedResponseSnapshot, value=event.response.to_dict())\n","sourceCodeStart":352,"sourceCodeEnd":373,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/streaming/responses/_responses.py#L352-L373","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nevents = [\"response.output_item.added\", ...]\n\n// after\nevents = [\"response.created\", \"response.output_item.added\", ..., \"response.completed\"]","handlingStrategy":"validation","validationCode":null,"typeGuard":"def starts_with_created(events: list[str]) -> bool:\n    return bool(events) and events[0] == \"response.created\"","tryCatchPattern":"try:\n    stream = client.responses.stream(...)\nexcept RuntimeError as e:\n    if \"response.created\" in str(e):\n        raise ValueError(\"event source violates Responses streaming protocol\") from e\n    raise","preventionTips":["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."],"tags":["streaming","responses","event-order"],"backgroundTag":"stream-event-order-violation","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}