> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ruapi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Codex: “stream disconnected before completion” — how to fix it

> “stream disconnected before completion” in Codex: what the text after the colon means, what to check in your network, and how to run Codex with an API key.

**Short answer:** `stream disconnected before completion` in Codex means the request to the model didn't finish: the connection closed, no data came for too long, or the server sent an error inside the stream. The reason is written after the colon, so start there. Codex retries on its own (up to 5 times by default), so you can simply wait out a rare disconnect. If it keeps happening, check your network and proxy. And if Codex can't connect to OpenAI's servers from your address, you can connect it with an API key to RuAPI, an independent API gateway that works from Russia — then you need neither a ChatGPT login nor a VPN.

## What the text after the colon means

| Text | What it means | Where to start |
| - | - | - |
| `stream closed before response.completed` or `websocket closed by server before response.completed` | The connection closed before the final event arrived. It may have been closed by the server or by something in between: a proxy, a VPN, an antivirus that inspects HTTPS, a router | Network and proxy — [below](#what-to-try) |
| `idle timeout waiting for SSE` or `idle timeout waiting for websocket` | No data for longer than the idle limit. The default is 300,000 ms, which is 5 minutes | Retry; if the task is very large, split it |
| `error sending request for url (…)` | Codex couldn't send the request to the address in the brackets. Newer CLI versions usually show this as a separate line, `Connection failed: …` | Open that address from the same computer; check your proxy |
| `Incomplete response returned, reason: content_filter` | The model's content filter stopped the reply | Rephrase the request |
| Other text | Usually the server's own message, for example about a limit or a balance | Do what it says |

Apart from `error sending request`, the wording comes from the Codex source code ([error.rs](https://github.com/openai/codex/blob/main/codex-rs/protocol/src/error.rs), [responses.rs](https://github.com/openai/codex/blob/main/codex-rs/codex-api/src/sse/responses.rs), [responses\_websocket.rs](https://github.com/openai/codex/blob/main/codex-rs/codex-api/src/endpoint/responses_websocket.rs)), checked on 25 November 2026.

## What to try

**1. Let Codex retry**

While you see “Reconnecting…”, Codex is trying again by itself. According to the [configuration reference](https://developers.openai.com/codex/config-reference), it retries an interrupted stream up to 5 times (`stream_max_retries`) and a failed request up to 4 times (`request_max_retries`).

**2. Update Codex and run the check**

`codex update` installs the latest version (if Codex was installed by the RuAPI command, update it [as described here](https://docs.ruapi.ai/en/integrations/codex.md#troubleshooting)). `codex doctor` checks the installation, configuration and login.

**3. Check your proxy**

Leftover `HTTP_PROXY`, `HTTPS_PROXY` or `ALL_PROXY` variables are sometimes the cause: the proxy is off or has moved to another port, but Codex still goes through it. That's what happened to users in [this GitHub thread](https://github.com/openai/codex/issues/26764). Look in `~/.codex/.env` as well.

**4. Try another network**

A different Wi-Fi or a phone hotspot shows at once whether the network is the problem. Turn off HTTPS inspection in your antivirus for a while.

**5. Pick up where you left off**

`codex resume --last` opens the most recent session.

## If Codex can't reach OpenAI's servers

With a ChatGPT login, Codex sends requests to `chatgpt.com` — you can see the address in the error: `error sending request for url (https://chatgpt.com/backend-api/codex/responses)`. If it isn't reachable from your network, retrying won't help.

With a RuAPI key, Codex sends requests to `https://www.ruapi.ai/v1` and no ChatGPT account is involved. RuAPI works from Russia without a VPN.

**1. Account and key**

Sign up at [www.ruapi.ai](https://www.ruapi.ai/?lng=en\&utm_source=docs\&utm_campaign=en-codex-stream-disconnected) with email, Google or Yandex. Key: Console → **API Keys** → **Create API key**.

**2. Balance**

Console → **Wallet**: USDT or USDC, from 5 USDT. No USDT yet? [Buy it with rubles via SBP](https://docs.ruapi.ai/en/buy-usdt.md). Cards from foreign banks (Visa / Mastercard) are accepted too.

**3. Codex**

With one command or manually in `config.toml` — see [Codex CLI](https://docs.ruapi.ai/en/integrations/codex.md).

You pay per token; no ChatGPT subscription is needed for this. How the two differ: [Codex in Russia](https://www.ruapi.ai/codex-v-rossii?lng=en\&utm_source=docs\&utm_campaign=en-codex-stream-disconnected). The `/model` menu has GPT models as well as Claude, DeepSeek, Gemini and others.

## FAQ

> [accordion] Is it because I hit my limit?
>
> Usually not: Codex reports a subscription limit in different words. But if the text after the colon mentions a limit or a balance, that is the reason.

> [accordion] How is this different from “Selected model is at capacity”?
>
> “At capacity” means OpenAI's server reported an overload — see [Codex: Selected model is at capacity](https://docs.ruapi.ai/en/codex-model-at-capacity.md). Here the request simply didn't finish.

> [accordion] I get disconnects with a RuAPI key too. What should I do?
>
> Update Codex and check your proxy and antivirus using the steps above. If that doesn't help, send [support](https://t.me/RuAPI_Support) the full error text, the model name and the time of the request.

> [accordion] Can I keep the ChatGPT login as well?
>
> Yes. The provider is set by the `model_provider` line in `config.toml`; [CC Switch](https://docs.ruapi.ai/en/integrations/ccswitch.md) makes switching easier.

## Next

> [card] [Codex CLI setup](https://docs.ruapi.ai/en/integrations/codex.md)
>
> With one command or config.toml.

> [card] [Codex: Token exchange failed](https://docs.ruapi.ai/en/codex-token-exchange-failed.md)
>
> Can't sign in to Codex.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.