{"record":{"id":"6127db38922932c2","repo":"openai/openai-python","slug":"didn-t-receive-a-response-completed-event","errorCode":null,"errorMessage":"Didn't receive a `response.completed` event.","messagePattern":"Didn't receive a `response\\.completed` event\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/openai/lib/streaming/responses/_responses.py","lineNumber":85,"sourceCode":"    ) -> None:\n        self.close()\n\n    def close(self) -> None:\n        \"\"\"\n        Close the response and release the connection.\n\n        Automatically called if the response body is read to completion.\n        \"\"\"\n        self._response.close()\n\n    def get_final_response(self) -> ParsedResponse[TextFormatT]:\n        \"\"\"Waits until the stream has been read to completion and returns\n        the accumulated `ParsedResponse` object.\n        \"\"\"\n        self.until_done()\n        response = self._state._completed_response\n        if not response:\n            raise RuntimeError(\"Didn't receive a `response.completed` event.\")\n\n        return response\n\n    def until_done(self) -> Self:\n        \"\"\"Blocks until the stream has been consumed.\"\"\"\n        consume_sync_iterator(self)\n        return self\n\n\nclass ResponseStreamManager(Generic[TextFormatT]):\n    def __init__(\n        self,\n        api_request: Callable[[], Stream[RawResponseStreamEvent]],\n        *,\n        text_format: type[TextFormatT] | Omit,\n        input_tools: Iterable[ToolParam] | Omit,\n        starting_after: int | None,\n    ) -> None:","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/streaming/responses/_responses.py#L67-L103","documentation":"Raised by get_final_response on a Responses API streaming run: after until_done() drains the stream, no response.completed event was ever captured into _state._completed_response. The Responses protocol always terminates a successful stream with response.completed; its absence means the stream ended abnormally (connection cut, error event, or early break by the caller).","triggerScenarios":"Calling get_final_response() after the SSE connection dropped mid-stream, after the server sent an error/failed event instead of response.completed, or after breaking out of the event loop before completion (so until_done cannot see the terminal event).","commonSituations":"Network interruptions during long Responses streams; proxies/load balancers with idle timeouts killing SSE; using stream=False semantics expectations with stream=True; early client-side cancellation; beta API changes.","solutions":["Check for APIError/connection errors raised while iterating; retry the request on abnormal termination","Increase or disable idle/read timeouts (client.with_options(timeout=...)) for long generations","Do not break out of stream iteration before the terminal event if you need the final response","Verify on a current SDK version and stable API version; report persistent premature terminations"],"exampleFix":"# before\nresponse = stream.get_final_response()  # raises if stream was cut\n\n# after\ntry:\n    response = stream.get_final_response()\nexcept RuntimeError:\n    response = client.responses.create(..., stream=False)  # retry non-streaming","handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    response = stream.get_final_response()\nexcept RuntimeError as e:\n    if \"response.completed\" in str(e):\n        response = client.responses.create(model=model, input=input)  # non-streaming retry","preventionTips":["Set generous read/idle timeouts for long streams (with_options(timeout=...))","Do not break out of stream iteration before the terminal event","Catch and log transport errors during iteration; retry on abnormal termination","Verify stable API/SDK version pairing for the Responses API"],"tags":["responses","streaming","sse","incomplete-stream","python"],"backgroundTag":"incomplete-event-stream","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}