Codex CLI "stream disconnected before completion": what to try
When Codex CLI gives up after "Reconnecting... 5/5" with a stream disconnect, narrow the cause by target, network, transport and retries. No fix is confirmed.
stream disconnected before completion: error sending request for url (https://chatgpt.com/backend-api/codex/responses)That single line is the title of the official repo issue #10985, verbatim. Comments in the same issue report Reconnecting... 1/5 through 5/5 being printed in turn before this line and then stopping. The wording says error sending request, that is, sending the request failed. Whether the request never reached the server or the response was cut off midway cannot be told from this message alone.
Up front: no single fix is confirmed for this error. The official docs have no entry for this message, and the official repo issues (#13245, #10985 and others) collect the same symptom from several different causes. The steps below narrow the cause; which one helps depends on your setup.
This is not like 429 or 401, where the server states a reason. For those, see Fix Codex CLI 429 and Fix Codex CLI 401.
[1] Check the version. Reports in these issues range from 0.106.0 to 0.142.2.
$ codex --versioncodex-cli 0.162.1If you are behind, update and retry. No issue confirmed an update as the fix.
[2] Read the URL in the message to see where the connection was going.
| Target | Meaning |
|---|---|
https://chatgpt.com/backend-api/codex/responses | The ChatGPT-login path to OpenAI. Go to steps 3 to 5 |
| A local address (for example a model server you run) | A failure on that server or on the Codex side. Check whether the request shows up in the server's logs first |
In #13245 one user running a local llama.cpp server reported that no request reached the server at all. That points to a failure before the request was sent, on the Codex side, not the server closing the connection. The issue does not confirm a cause.
[3] Try without a VPN, proxy or firewall. In #13245 a maintainer said the logs looked like "a basic network connectivity issue", often seen with VPNs and proxies, and the issue carries the connectivity label. The maintainer also asked about corporate proxies and firewalls. Another user there reported it about once an hour on a wired connection with Tailscale, so it also happens without a proxy.
#13041 also has a macOS report. On the same Mac, curl -4vI https://chatgpt.com resolved the host but failed with No route to host, and turning off "Private Wi-Fi Address" for that network fixed it immediately (it worked on a phone hotspot). Another user there had a fixed Wi-Fi address set, no VPN, and still hit the error, and nothing is officially confirmed, so use it only as a check: does it work on a different network, such as a hotspot?
[4] If WebSocket text appears next to it, the transport may be involved. One line posted in #13041:
Falling back from WebSockets to HTTPS transport. stream disconnected before completion: websocket closed by server before response.completedIn that issue a maintainer wrote on 2026-02-28: "We've fixed a few problems on the server side that we think should address most (all?) of the problems that have been reported." They asked anyone still affected to upload logs with /feedback. Comments with the same symptom kept arriving afterwards, the issue was closed as "completed" on 2026-08-05, and no linked fix commit was found. One user reported it with ChatGPT login but not with API key authentication.
The same issue contains a community workaround. It is not official guidance. The user who posted it described it as forcing HTTPS transport until the WebSocket path is fixed, and claimed that features.responses_websockets = false alone is not enough because Codex can still pick WebSockets depending on model metadata, so you define an HTTP-only provider instead. The supports_websockets key does exist in OpenAI's config reference.
model_provider = "openai_http" [model_providers.openai_http]name = "OpenAI HTTP only"wire_api = "responses"requires_openai_auth = truesupports_websockets = falsebase_url = "https://chatgpt.com/backend-api/codex"Restart Codex after editing the config so it reloads. This configuration was not tested here. Another user in the same issue wrote that a workaround linked from #13103 worked but was much slower than with WebSockets, and it was not confirmed whether that is the configuration above. Also, a 2026-06-26 comment in #10985 reports Request failed ... error sending request for url (...) in logs showing transport="responses_http", so switching to HTTP does not fix every case.
[5] On a custom provider, raise retries and the timeout. These are the model_providers.<id> keys in the config reference.
[model_providers.<id>]request_max_retries = 4 # HTTP request retries (documented default 4)stream_max_retries = 5 # SSE stream interruption retries (documented default 5)stream_idle_timeout_ms = 300000 # SSE idle timeout in ms (documented default 300000)<id> is the name of the provider table you defined. In #13245 one user wrote that setting request_max_retries and stream_max_retries to 100 mostly avoided the error on an Azure provider, and said they did not know whether it works elsewhere. The 5/5 on screen looks like the documented stream_max_retries default of 5, but the docs do not describe that link. The docs also say the built-in provider IDs (openai, ollama, lmstudio) are reserved and cannot be overridden, so you cannot put these keys on the default openai provider. A provider defined under a new ID, as in step 4, can carry the same keys, but no report was found that doing so reduced this error.
[6] Try another model with codex -m <model>. Several reports say switching models helped for a while, others say only briefly, and one user guessed a hidden rate limit. None of this is a confirmed cause.
[7] If it persists, leave logs the way the issues ask. A maintainer repeatedly said the problem cannot be diagnosed without logs and asked users to upload them with /feedback and post the thread ID in the issue. Restarting, signing out and back in, and resuming sessions mostly did not help in the reports, and one user could not log in again after logging out (Token exchange failed), so log out last.