Blog

Codex "stream disconnected before completion": What It Means and How to Fix It

Short answer

stream disconnected before completion means the response stream for a Codex turn ended, or failed, after the request was accepted but before the model's response finished. It isn't one specific error. Codex puts the real reason after the colon, and that part tells you what to do:

Text after the colon What it points to
error sending request for url (...), os error 10053, os error 10061 Your network, VPN, proxy or firewall
stream closed before response.completed The connection closed mid-response, somewhere between you and the server
idle timeout waiting for SSE No data arrived for the idle timeout (5 minutes by default)
An error occurred while processing your request. ... request ID ... An error on the server side
Rate limit reached for ... / Request too large for ... A tokens-per-minute or requests-per-minute limit

Codex retries on its own first, which is the Reconnecting... 1/5 line you see before the error. If the error comes back once in a while, retrying the turn is fine. If it comes back every time, use the text after the colon to find the cause.

What the error looks like

The message is defined in Codex's source (codex-rs/protocol/src/error.rs) as stream disconnected before completion: {reason}, for a stream that disconnects or errors after the HTTP handshake succeeded but before response.completed. Codex treats it as transient and retries the turn.

While retrying, you see a counter, as in openai/codex#47538:

text
Reconnecting... 1/5 (stream disconnected before completion: stream closed before response.completed)

When the retries run out, Codex may switch from WebSockets to HTTPS and try again (#38366, shortened):

text
⚠ Falling back from WebSockets to HTTPS transport. stream disconnected before completion: Request too large for gpt-5.6-luna in organization org-... on tokens per min (TPM): Limit 200000, Requested 208334. The input or output tokens must be reduced in order to run successfully.

Other reasons reported in the Codex issue tracker:

text
stream disconnected before completion: error sending request for url (https://chatgpt.com/backend-api/codex/responses)
stream disconnected before completion: IO error: An established connection was aborted by the software in your host machine. (os error 10053)
stream disconnected before completion: No connection could be made because the target machine actively refused it. (os error 10061)
stream disconnected before completion: idle timeout waiting for SSE
stream disconnected before completion: An error occurred while processing your request. You can retry your request, or contact us through our help center at help.openai.com if the error persists. Please include the request ID <id> in your message.

Sources: #38212, #54459, #49466, #53578 and #53557.

The URL in a message also tells you which endpoint Codex was using: chatgpt.com/backend-api/codex/... when you're signed in with ChatGPT, api.openai.com/v1/... with an OpenAI API key, or your provider's base_url with a custom provider.

Causes and fixes by reason

Network: error sending request, os error 10053, os error 10061

Codex couldn't send the request, or your machine closed the connection.

  • os error 10061 (connection refused) on Windows. Nothing answered at the address Codex tried. If Codex goes through a local proxy, check that the proxy is running and listening on the port Codex uses, or remove the setting that points Codex at it.
  • os error 10053 on Windows. Software on your machine aborted the connection: a firewall, antivirus, VPN client or proxy. Test with them paused, then add an exception for Codex.
  • error sending request for url. DNS, proxy or network failure before the request got out. Check that the host in the URL resolves and is reachable from the same terminal.

Run codex doctor to see the environment Codex is running in. Then test the host from the URL in the message from the same terminal, for example curl -I https://chatgpt.com or curl -I https://api.openai.com/v1/models. Any HTTP status means the host is reachable; a connection error means the network path is the problem, not Codex.

Mid-stream drop: stream closed before response.completed

The response had started, then the connection closed before the final event. Anything between you and the server can do this: an unstable Wi-Fi link, a VPN switching nodes, a proxy that cuts long connections, or the server itself.

  • If it happens now and then, let Codex retry, or send the turn again.
  • If it happens often on one network, try another network or test without the VPN or proxy.
  • If you use a custom provider or gateway, check its logs for the request. A gateway in the middle can close the stream too.

Idle timeout: idle timeout waiting for SSE

No events arrived on the stream for the idle timeout. Long reasoning or a stalled connection can cause it. For a custom provider, the timeout is stream_idle_timeout_ms (default 300000, which is 5 minutes) in the provider's block in ~/.codex/config.toml, per the configuration reference.

Server error: An error occurred while processing your request

The server returned an error after the stream had started. Retry the turn. If it keeps happening, report it with /feedback and include the request ID from the message.

Reports often cluster: #45949, #45965, #46161 and #46248 were all filed on September 16–17, 2026. In #45925, one user measured a failure rate that changed with the ChatGPT account they were signed in with, on the same machine and network. If your setup didn't change and the error started suddenly, check the issue tracker before you change anything locally.

Rate limit or request size: Rate limit reached / Request too large

The text names a tokens-per-minute (TPM) or requests-per-minute (RPM) limit.

  • Rate limit reached for ... Please try again in 13.694s (#10060) is temporary. Wait the stated time.
  • Request too large for ... The input or output tokens must be reduced in order to run successfully. means one request is bigger than the whole per-minute limit, so waiting won't help. In #38366, Codex kept resending a 208K-token request against a 200K TPM limit. Start a new thread, or run /compact to shrink the conversation.

For the API-side details, see OpenAI API 429 "Rate limit reached".

Tune retries and timeouts for a custom provider

When Codex uses a provider you define under [model_providers.<id>], you can set these keys in its block. Defaults are from the configuration reference; the advanced configuration page has an example:

Key Default What it does
request_max_retries 4 Retries for the HTTP request to the provider
stream_max_retries 5 Retries after the stream is interrupted
stream_idle_timeout_ms 300000 How long a stream may stay silent before Codex treats it as dead

More retries help on a network that drops connections now and then. They don't help when the reason is a request that's too large, or a setting that's wrong.

Using Codex with a TeamoRouter key

TeamoRouter is an API gateway with one key for GPT, Claude, Gemini and DeepSeek. It speaks the OpenAI Responses API (/v1/responses), so Codex connects to it as a custom provider. There's no subscription; you pay per use.

  1. Create an API key in the TeamoRouter console. It starts with sk-teamo-.
  2. Top up from $5. The top-up dialog takes cards. You can also click Pay with crypto and pay with USDT, USDC or ETH from any exchange app — the checkout shows which networks your amount supports (BEP20 works from $5). Step by step: Pay with USDT.
  3. Add the provider to ~/.codex/config.toml. The last two lines are optional:
toml
model_provider = "teamorouter"
model = "gpt-6-sol"

[model_providers.teamorouter]
name = "TeamoRouter"
base_url = "https://api.teamorouter.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"
stream_max_retries = 10
stream_idle_timeout_ms = 300000
  1. Set the key and test the path from the terminal you'll run Codex in:
bash
export OPENAI_API_KEY="sk-teamo-..."
curl https://api.teamorouter.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY"

A model list means the path and key work. Start codex from the same shell. Windows commands are in Install and connect Codex.

FAQ

Is "stream disconnected" a network problem? Sometimes. It's a wrapper around many reasons. Read the text after the colon: os error codes and error sending request are network problems, while Rate limit reached and An error occurred while processing your request are not.

Does Codex retry automatically? Yes. The Reconnecting... N/5 line is Codex retrying. After the retries, it may fall back from WebSockets to HTTPS before showing the error.

Will logging out and back in fix it? Not for network or rate-limit reasons. It only matters if the problem follows your account, as reported in #45925.

Why does it happen during "remote compact task"? Compaction is a request too, so it can fail for the same reasons. A message such as Error running remote compact task: stream disconnected before completion: ... has the reason after the second colon.

Next steps

Ready to connect?Log in · top up · create an API key — three steps to start.