Client-sideLocal network & connectionCodex CLICC Switch

Fix Codex "stream disconnected before completion"

Error message
stream disconnected before completion: stream closed before response.completed

Codex keeps showing Reconnecting... 1/5 and then fails with stream disconnected before completion: the SSE stream dropped before response.completed arrived. Check the url in the error, get local proxies out of the way, keep single turns under five minutes, and raise stream_max_retries.

Fix it in 3 steps

  1. 1

    Check that the url in the error is CCSub

    The address inside error sending request for url (...) should be https://www.ccsub.net/api/v1/responses. If it's anything else, your config was overwritten or isn't applied; fix ~/.codex/config.toml first.

  2. 2

    Take local proxies out of the path

    Check HTTPS_PROXY / HTTP_PROXY / ALL_PROXY in your shell and any TUN or global mode in your proxy app. CCSub is reachable directly, so exempt ccsub.net with NO_PROXY or a direct rule and long-lived streams won't be cut by a proxy node.

  3. 3

    Raise retries and shorten single turns

    Set stream_max_retries (default 5) and request_max_retries (default 4) in [model_providers.ccsub]. A single turn that runs past five minutes gets cut off server-side, so lower model_reasoning_effort a notch or split big tasks into steps.

Other forms of the same error

  • stream disconnected before completion: error sending request for url (https://www.ccsub.net/api/v1/responses)
  • Reconnecting... 2/5

How this error happens

Codex receives results from the Responses API as a server-sent event (SSE) stream, and every turn has to end with a response.completed event. If the connection closes before that event arrives, Codex reconnects on its own, showing Reconnecting... 1/5, and once it runs out of attempts it prints stream disconnected before completion. The text after the colon tells you which kind of failure it was:

  • stream closed before response.completed — the connection was up and some data arrived, but the stream closed before the end.
  • error sending request for url (...) — the request never went out or no response headers came back. The parentheses show the address Codex actually tried.

When OpenAI maintainers answered similar reports on the Codex issue tracker, the causes they pointed to were all at the network layer: firewalls, proxies interfering with TLS, VPNs, DNS, corporate network restrictions, and misconfigured provider settings. The same list applies when Codex talks to CCSub.

Cause 1: wrong or overwritten URL

Look at the address in error sending request for url (...) first. For CCSub it should be https://www.ccsub.net/api/v1/responses. If it isn't:

  • model_provider or base_url in ~/.codex/config.toml is wrong, or a top-level key ended up under a table header (see the TOML notes on the Codex 401 page).
  • A switcher like CC Switch changed providers and rewrote the config to a different address.

Cause 2: a local proxy cuts the long connection

A streaming response is a single connection that stays open for tens of seconds to several minutes, which makes it much easier for a proxy node to drop than an ordinary request. If your shell has HTTPS_PROXY or similar set, or your proxy app runs in TUN or global mode, the request detours through a proxy node and back. The longer the path, the more likely it breaks mid-stream. CCSub can be reached directly:

env | grep -i proxy                       # any proxy variables set?
export NO_PROXY="www.ccsub.net,ccsub.net"  # send CCSub direct

In Clash-style proxy apps, add a DOMAIN-SUFFIX,ccsub.net,DIRECT rule.

Cause 3: the turn simply runs too long

A single request on CCSub can last about five minutes. A turn with very high reasoning effort that also writes lots of files can blow past that, and the server cuts the stream before it finishes — you'll see stream closed before response.completed. To avoid it:

  • Lower model_reasoning_effort one step at the top of config.toml, for example from high to medium.
  • Ask Codex for one thing at a time and split large refactors into stages.
  • Compact or start a new session when the conversation gets very long, so each turn sends less input.

Raise Codex's retry settings

Codex's configuration lets each model provider set its own retry and timeout values: stream_max_retries is how many times it reconnects after a stream drops (default 5), request_max_retries is HTTP request retries (default 4), and stream_idle_timeout_ms is the streaming idle timeout (default 300000 ms). On a slightly flaky network, higher retry counts let Codex ride out the blips:

[model_providers.ccsub]
name = "CCSub"
base_url = "https://www.ccsub.net/api/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"
request_max_retries = 6
stream_max_retries = 10
stream_idle_timeout_ms = 300000

More retries only paper over occasional drops. If every single turn reconnects all the way to the limit, one of the three causes above is the real problem, and no retry count will fix it.

FAQ

What does "Reconnecting... 1/5" mean?

Codex is reconnecting after the stream broke; the denominator is stream_max_retries, 5 by default. One or two reconnects that then recover are nothing to worry about. If every turn climbs to 5/5 and fails, work through this page.

Why does Codex fail while Claude Code works fine?

They use different endpoints and timeouts. Codex streams from the Responses API and only treats a turn as finished once response.completed arrives, so any mid-stream drop surfaces as this error. The same network issue in Claude Code usually shows up as a Connection error or a silent retry.

How long can a single turn run?

A single request on CCSub can run for about five minutes. A turn with very high reasoning effort and a large output can exceed that and get cut before it completes. Codex's own stream idle timeout, stream_idle_timeout_ms, also defaults to five minutes.

Am I billed when the stream drops?

CCSub bills the usage the upstream reports in the stream. If it drops mid-way, usage already reported before the cut may still count; requests that fail before any response starts aren't billed.

Still stuck?

New to CCSub?

Sign up, create an API key in the dashboard, and paste it into Claude Code, Codex CLI or your editor. You pay for what you use.