LLM API Guide

Fix "stream disconnected before completion" Overload in Codex and sub2api

Fix the mid-stream "stream disconnected before completion: Our servers are currently overloaded. Please try again later." error in Codex and sub2api.

Summary

  1. The error means the initial connection succeeded.
  2. On sub2api and pooled Pro/Team relays.
  3. Lower single-account concurrency to 1 or 2, space requests by 5 to 15 seconds, enable channel fallback.

When Codex CLI stops mid-turn and prints stream disconnected before completion: Our servers are currently overloaded. Please try again later., your request did not fail at the initial connection stage. The HTTP handshake succeeded, the upstream server accepted your prompt, and the response stream was already open—either in the middle of a reasoning block or partway through streaming tokens—when the connection was cut before the client received the final response.completed lifecycle event.

In the OpenAI Codex client source code, any drop that occurs after a stream starts is wrapped in the stream disconnected before completion: {reason} prefix. The second half of the message (Our servers are currently overloaded. Please try again later.) is an upstream HTTP 503 or 502 overload payload injected into the closing frame. Codex treats this as a transient failure and immediately enters its built-in reconnect loop (Reconnecting... 1/5), which often fails four more times in a row if you do not address what triggered the drop.

How you fix this depends entirely on how you connect to the model. If you call OpenAI directly with a standard platform API key, you are hitting genuine cluster congestion. If you route Codex CLI through sub2api or another gateway that pools ChatGPT Pro or Team subscriptions, OpenAI's global infrastructure is almost certainly fine—your gateway just tripped per-account concurrency or burst-rate limits.

On this page

Direct OpenAI API vs. sub2api Subscription Gateways

When you look up a 503 overload error in the OpenAI API error code documentation, the standard advice is to check the OpenAI Status Page, wait a few minutes, and add exponential backoff. That advice applies when you use an official Tier 1–5 API key against api.openai.com, where sudden traffic spikes or regional node scaling can drop long-running streams during peak US working hours.

In sub2api setups, the same error message masks a different mechanism. When a relay mounts multiple ChatGPT Pro (20x) or Team accounts and exposes them as an OpenAI-compatible endpoint, OpenAI monitors the request cadence of each underlying subscription. A human using the web interface does not fire parallel tool-calling streams or send a new 80,000-token prompt every second after a command finishes.

When a single Pro account inside sub2api handles even 3 concurrent streams—or receives back-to-back requests separated by less than a second—upstream heuristics flag that account for automated abuse. Instead of banning the account outright or returning a standard 401, the upstream server begins severing active streams mid-generation with Our servers are currently overloaded. Please try again later.. Once an account gets tagged with this throttling penalty, rotating your server's outbound IP address across regions (for example, switching proxies from US East to Europe) will not clear the error, because the restriction stays attached to the account session itself. If you are also seeing pre-stream rejections before the connection even opens, compare that behavior with our guide on Codex "Selected Model Is at Capacity": OpenAI Load or Your Account?.

Connection Setup Primary Trigger Behind the Overload Message What Happens When Codex Auto-Retries Effective Fix
Direct OpenAI API (api.openai.com) Regional compute saturation or long xhigh reasoning turns exceeding upstream worker windows Succeeds if load drops within 10–30 seconds; fails during sustained outages Lower reasoning effort, compact context, wait 5+ seconds between manual retries
sub2api / Pooled Pro Accounts Single-account concurrency (>2 active streams) or sub-second request bursts triggering account-level throttling All 5 retries hit the same flagged account and fail immediately Cap per-account concurrency at 1–2, enforce 5–15s request pacing, enable channel fallback
Custom Nginx Reverse Proxy + Gateway Proxy timeout or response buffer saturation colliding with upstream slow-downs Stream hangs for minutes before throwing a disconnect Disable proxy_buffering and extend proxy_read_timeout to 300s

Check Your Working Tree Before You Retry

Before you press Enter to re-run the failed prompt, inspect git status and git diff in your project directory. Because this disconnect happens after the turn starts, Codex CLI has often finished running local shell commands, modifying files, or executing MCP tool calls right before the final summary stream gets cut off.

A dropped stream does not roll back local filesystem changes or external API actions that happened earlier in the turn. If your prompt asked the agent to run a database migration, append configuration blocks, or refactor a module, blindly repeating the prompt can execute those commands a second time. When you resume, start a fresh short read-only check or tell Codex which file edits are already on disk so it picks up from the current state instead of starting over.

Tuning sub2api to Stop Per-Account Overload Drops

If you run or manage a sub2api instance, waiting for the error to go away on its own rarely works because normal coding agent traffic keeps re-triggering the account penalty. You need to shape how the gateway dispatches requests to upstream subscriptions.

  1. Drop single-account concurrency (Account Concurrency) to 1 or 2. Even when a 20x Pro account has plenty of weekly quota left, running 3 or more simultaneous streams on a single credential reliably triggers mid-stream overloaded disconnects. Set the hard per-account concurrency ceiling to 1 (or at most 2) in the sub2api account settings, and enable per-API-key concurrency limits so a single developer running multi-agent loops cannot saturate the pool.
  2. Add a 5-to-15-second pacing interval between requests on the same account. Coding agents like Codex CLI parse tool output and fire the next API request within milliseconds. When a single account receives requests at a 1-request-per-second cadence, it trips upstream rate protection and starts returning 502s and mid-stream overload errors. Queue excess downstream requests briefly or spread them across a wider account pool so each individual credential rests for 5 to 15 seconds between turns.
  3. Configure Channel Fallback and Model Fallback. By default, when Codex CLI sees a stream disconnect, it retries 5 times in rapid succession. If sub2api routes all 5 retries back to the same throttled Pro account, every retry fails and the session crashes. Enable channel fallback in your gateway routing rules so that any upstream returning an HTTP 503 or mid-stream overload error is temporarily placed in cooldown, and the retry is silently routed to a clean backup channel or fallback model. If your gateway returns hard 503 headers before streaming starts, see How to Fix unexpected status 503 Service Unavailable Upstream Service Error.

If you place an Nginx reverse proxy in front of sub2api, verify that your proxy layer is not compounding the problem by buffering Server-Sent Events or closing idle sockets while the model thinks. Add these directives to your Nginx location block:

nginx
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 300s;
proxy_send_timeout 300s;

For drops where the stream closes cleanly without an explicit overload message (stream closed before response.completed), check our walkthrough on fixing stream disconnected (response.completed) in Codex CLI and sub2api.

Reducing Stream Duration and Context Load in Codex CLI

Even on a well-tuned gateway—or on a direct OpenAI connection—the probability of a stream getting terminated by an overload event rises sharply with the duration of the generation and the size of the input payload.

Lower Reasoning Effort on Heavy Turns

When you run deep reasoning tiers (high or xhigh effort), the model can spend over 150 seconds generating internal reasoning tokens before emitting a single visible character. Upstream load balancers under heavy traffic preferentially shed long-running, compute-heavy connections first.

If a task keeps disconnecting mid-stream, run /model inside your Codex CLI session and step the reasoning effort down one level—from xhigh to high, or from high to medium. Keeping individual turn generation under 60 to 90 seconds drastically reduces the window during which an upstream capacity spike can sever your connection.

Shrink the Active Session Context

Long coding sessions accumulate tens of thousands of tokens of file reads, diff outputs, and terminal logs. Pushing a bloated context window on every turn spikes Time-to-First-Token (TTFT) and holds the upstream worker slot open much longer. Run compact commands regularly, start a clean session once a feature subtask is finished, and move static repository instructions into AGENTS.md rather than pasting large reference files into the chat history.

Adjust ~/.codex/config.toml Retry Settings Without Over-Retrying

According to the Codex configuration reference, Codex CLI controls stream recovery using three parameters in ~/.codex/config.toml: request_max_retries (defaults to 4), stream_max_retries (defaults to 5), and stream_idle_timeout_ms (defaults to 300000, or 5 minutes). When Codex exhausts its WebSocket stream retries, it automatically attempts to downgrade the transport layer (Falling back from WebSockets to HTTPS transport).

You can customize these values for your provider in ~/.codex/config.toml:

toml
[model_providers.custom_gateway]
name = "Custom Gateway"
base_url = "https://your-gateway.example.com/v1"
env_key = "OPENAI_API_KEY"
request_max_retries = 4
stream_max_retries = 5
stream_idle_timeout_ms = 300000

Be careful with stream_max_retries. Raising stream_max_retries to 8 or 10 helps when you connect directly to OpenAI and want the CLI to ride out brief 5-second cluster blips without aborting your turn. However, if you are connected to a sub2api pool without automatic channel failover, increasing stream_max_retries only forces your client to hammer a flagged account ten times in a row, extending the lock duration and hanging your terminal. Leave stream_max_retries at 5 (or lower it to 3) on subscription gateways, and let the gateway handle channel rotation.

When your primary sub2api pool is saturated or an account cooldown leaves you blocked mid-task, the fastest workaround is switching Codex CLI to a backup relay or an official direct API key. If you do not want to edit ~/.codex/config.toml and environment variables by hand every time an endpoint overloads, you can use our open-source LLM API Config GUI for Codex and Claude Code to test endpoint health and swap Base URLs and API keys in one click.

Sources and checks

  1. OpenAI Codex client source code
  2. OpenAI API error code documentation
  3. OpenAI Status Page
  4. Codex configuration reference