How to Fix unexpected status 503 Service Unavailable Upstream Service Error
Fix "unexpected status 503 Service Unavailable: The upstream service returned an error. Please try again later." when using OpenAI models and sub2api.
Summary
- This 503 error occurs during the initial HTTP handshake when an upstream model is overloaded or a reverse proxy translates an upstream failure.
- Inspect raw HTTP headers and error codes with curl to tell a genuine OpenAI server_is_overloaded event apart from a soft-blocked subscription account.
- Update sub2api to v0.2.18 or later to lock session fingerprints and respect Retry-After headers.
When Codex CLI or Claude Code exits with unexpected status 503 Service Unavailable: The upstream service returned an error. Please try again later., the failure is not coming from your local network or a broken CLI installation. It means the API gateway, reverse proxy, or subscription relay sitting between your terminal and the model provider tried to forward your prompt, received an error from the upstream server, and packaged that failure into an HTTP 503 response.
In my own gateway logs, this exact message almost always comes down to one of three things: a genuine capacity shortage on OpenAI or Anthropic servers, a reverse proxy translating an upstream rate or overload code into a generic 503, or a pooled ChatGPT Pro or Claude Pro account inside sub2api getting soft-blocked by upstream risk controls.
Unlike stream disconnected before completion: Upstream request failed or stream disconnected before completion: stream closed before response.completed, which drop your session partway through an active HTTP 200 stream, an unexpected status 503 kills the turn before a single token is generated. You have to find out which hop in the chain refused the handshake before you start changing client settings.
On this page
Why Your Client Sees an Upstream 503
According to the MDN HTTP 503 specification, a 503 status means a server is reachable but temporarily refusing to process the request. In an AI coding setup, however, your CLI rarely talks straight to a single origin server. Your request passes through Cloudflare, an API gateway such as sub2api, New API, or LiteLLM, and finally the upstream model endpoint. Any of those layers can trigger the error for a completely different reason.
| Actual Cause | Raw Upstream Status & Code | What Happens in Your Gateway / CLI |
|---|---|---|
| OpenAI model capacity shortage | HTTP 503 with type: "service_unavailable_error" and code: "server_is_overloaded" |
The gateway forwards the 503 or wraps it as The upstream service returned an error. Please try again later. |
| Anthropic server overload | HTTP 529 with type: "overloaded_error" |
Many OpenAI-compatible proxies and gateways do not pass non-standard 529 codes through, converting them into HTTP 503 for the client. |
Flagged Pro account in sub2api |
HTTP 503 (Our servers are currently overloaded. Please try again later.) on one specific account |
Upstream risk control throttles a single Pro 200 or pooled subscription account while other accounts on the same IP work normally. |
| Cloudflare edge or WAF block | HTTP 503 HTML body or Cloudflare Error 1010 / 5xx |
The edge blocks the proxy's request before it reaches the model API, or an older gateway misclassifies a 1010 block and starves the account pool. |
The third row is the trap that wastes the most debugging time. When you route Codex CLI through a multi-account relay like sub2api, you can have five ChatGPT Pro accounts sitting on the exact same server and IP address. Four of them will answer prompts in under a second, while one specific account—often an older Pro 200 subscription—returns 503 on every request. OpenAI's servers are not globally overloaded in that scenario; that specific account's session fingerprint has been flagged for temporary throttling.
Step 1: Rule Out a Global Provider Outage and Edge Blocks
Before touching your gateway configuration, check whether the upstream provider is actually having an incident. Open the OpenAI Status page if you are running Codex models, or check Anthropic's API error documentation and status monitor if you are calling Claude.
Per the OpenAI error code documentation, a genuine capacity shortage returns HTTP 503 with the server_is_overloaded code and often includes a Retry-After HTTP header telling the client how many seconds to wait. If you also see capacity warnings in the terminal, I wrote a separate breakdown on how to tell whether Codex's "Selected model is at capacity" error is OpenAI load or an account routing lock.
To see what your endpoint is actually returning behind the CLI's shortened error message, run a direct curl -i test against your configured Base URL so you can inspect both the response headers and the raw body:
curl -i https://your-gateway.example.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-5-codex",
"input": "ping"
}'
Look closely at three details in the output:
- The
Retry-Afterheader and response time: If the 503 comes back in under 50 milliseconds with no upstream request ID, your local reverse proxy or rate limiter rejected the call before contacting the provider. If it takes half a second to several seconds and carries aRetry-Afterheader, the upstream provider generated the rejection. - HTML vs. JSON payload: As noted in Cloudflare's 503 troubleshooting guide, an HTML error body containing
cloudflareorcloudflare-nginxmeans the failure happened at the Cloudflare edge or CDN layer, whereas a JSON payload without Cloudflare branding comes from the origin API or your gateway software. - Environment variable conflicts in Claude Code: If
curlsucceeds with a200 OKagainst your gateway but Claude Code still fails, your CLI session may be ignoring your proxy key and sending requests with a stale login token. Follow our guide on fixingANTHROPIC_BASE_URLnot working in Claude Code to make sureANTHROPIC_AUTH_TOKENis properly bound.
Step 2: Isolate Flagged Accounts in Your sub2api Channel Pool
If the official status pages are green and your curl test fails intermittently—for example, failing on one request and succeeding two seconds later—you almost certainly have a degraded upstream account inside your relay pool.
Do not try to brute-force past this by spamming retries in your terminal. According to the Claude Code release notes, the CLI only retries a 502, 503, or 504 error once before aborting the turn. Firing repeated manual retries without backoff against a gateway that routes you back to the same flagged account will only extend the upstream soft-block.
Open your sub2api or New API administration panel and go to your account or channel management view. Instead of testing the aggregated group key, run a health check on each upstream account individually. Watch the per-account error logs while sending a test prompt.
When a ChatGPT Pro or Claude Pro account is soft-blocked by upstream anti-abuse rules, its health check will immediately return 503 Our servers are currently overloaded. Please try again later. while sibling accounts in the same group pass with a 200. Pause or remove that specific account from the active dispatch group right away. Leaving a flagged account in rotation without proper failover guarantees that a percentage of your Codex CLI turns will crash with unexpected status 503 Service Unavailable.
Step 3: Upgrade sub2api to v0.2.18+ and Fix Retry Failover
If your Pro accounts keep getting flagged with 503 errors after a few hours of coding, the problem is usually how the gateway forwards headers and handles retries.
In versions of sub2api prior to v0.2.18, three gateway behaviors routinely triggered upstream 503 blocks on Codex and OpenAI Pro channels. First, the gateway did not lock a consistent client session fingerprint across turns, so slight variations in forwarded headers made a single coding session look like suspicious automated scraping. Second, when an upstream node returned a 503 with a Retry-After header, the gateway did not enforce the requested backoff window before hitting the account again. Third, if the upstream server returned an empty stream event or an in-stream error before any completion tokens were emitted, the retry logic stalled instead of silently switching to a healthy account in the pool. Even worse, older builds misclassified Cloudflare 1010 blocks as account 403 errors, temporarily disabling healthy accounts and forcing all traffic onto the remaining overloaded ones.
Updating sub2api to v0.2.18 or newer resolves these exact failure modes:
# Pull the latest sub2api image (v0.2.18+) and recreate the container
docker compose pull
docker compose up -d
Once you are on v0.2.18 or later, the gateway keeps client identity headers consistent for OpenAI and Codex sessions, honors Retry-After cooldowns so flagged accounts are not hammered into a harder ban, and automatically fails over to another account in your group if an upstream channel drops an empty stream or throws an error before token streaming starts.
For the Pro accounts that you paused in Step 2, leave them out of the active pool for at least a few hours so their upstream rate and risk counters reset. Once re-enabled behind the updated gateway, test them individually before putting them back into your main coding group. If an account never recovers from 503 responses and eventually switches to an authentication or organization block, check your inbox and follow our walkthrough on what the account disabled email means and how to appeal.