Back to Blog

Fix Codex Reconnecting 5/5 Error with HTTPS Streaming

Tutorials and Guides8828
Fix Codex Reconnecting 5/5 Error with HTTPS Streaming

Introduction

Many developers encounter a frustrating issue with the OpenAI Codex desktop client. After starting a new chat session, the program repeatedly tries to reconnect. The counter increments sequentially: Reconnecting… (1/5), (2/5), (3/5), (4/5), (5/5). Once the fifth attempt fails, the cycle resets back to 1/5 and repeats. In some cases, the client eventually falls back to an alternative transport and works, but users must wait 10 to dozens of seconds every time they open a new conversation. This delay significantly disrupts coding workflow and user experience.

Most users will initially blame this problem on common suspects: overloaded OpenAI servers, unstable network links, slow model response, or invalid API keys. In most instances, these assumptions are incorrect. The root of this issue lies in a transport layer change introduced in newer Codex builds. Modern Codex prioritizes WebSocket connections for the Responses API. Many corporate, campus or restricted network environments cannot reliably establish WebSocket (wss://) tunnels. This article breaks down the request pipeline, analyzes the underlying Rust source logic, and provides actionable configuration fixes.

1. Understand Codex Request Pipeline

Before troubleshooting, it is critical to understand the two transport modes supported by the Responses API. When a user submits a prompt inside Codex, the client sends requests to OpenAI backend services. The Responses API supports two distinct streaming transmission methods.

1.1 Method One: HTTPS Streaming (POST + SSE)

This is the classic and widely compatible streaming approach. The client sends an HTTP POST request, and the server returns continuous real-time content through Server-Sent Events (SSE). The connection uses standard HTTPS port 443. Most firewalls, corporate proxies and network gateways support this protocol without special configuration.

Many mainstream AI client applications rely on this transport method. Examples include Claude Code, Cherry Studio, and the official OpenAI Web UI. The biggest advantage of SSE streaming is its broad compatibility across restrictive network environments.

1.2 Method Two: WebSocket for Responses API

In 2026, OpenAI added native WebSocket support to the Responses API. WebSocket establishes a single persistent connection between client and server once handshaking completes. Data flows bidirectionally over this long-lived channel throughout the session.

Compared with HTTPS SSE streaming, WebSocket brings measurable performance improvements:

OpenAI’s official engineering blog has published dedicated content introducing WebSocket acceleration for agent workflows on the Responses API. The downside is that WebSocket connections use the wss:// scheme. Some network security rules block WebSocket handshakes while allowing regular HTTPS traffic to pass through.

2. Why the Reconnecting 5/5 Loop Occurs

This is the core of the failure. Many network environments exhibit asymmetric filtering behavior. Standard HTTPS requests work perfectly, but wss:// WebSocket handshake requests get blocked and time out.

Common network environments that exhibit this behavior:

When Codex starts a conversation, it follows this sequence automatically:

  1. Attempt to establish WebSocket connection
  2. Handshake request times out or is rejected
  3. Trigger retry counter increment
  4. Repeat the WebSocket connection attempt
  5. After 5 failed attempts, reset counter and restart the whole cycle

This behavior explains the UI message “Reconnecting…” and the 1 through 5 retry counter. In scenarios where the client eventually works, Codex automatically falls back to HTTPS SSE streaming after exhausting WebSocket retries. The long waiting time comes entirely from the 5 failed WebSocket handshake attempts.

3. How Codex Source Code Implements Transport Selection

Codex’s transport selection logic is written in Rust, located within client.rs and stream.rs. The simplified code logic for transport selection follows this decision tree.

rust
if wire_api == Responses {
    if responses_websocket_enabled() {
        use WebSocket
    } else {
        use HTTPS Streaming
    }
}

The first condition checks whether the active API in use is the Responses API. If true, the program then evaluates the boolean return value of responses_websocket_enabled(). If this function returns true, the client will use WebSocket transport. If false, it switches over to HTTPS SSE streaming.

4. What Controls WebSocket Activation

The function responses_websocket_enabled() contains the key judgement logic. Its simplified implementation is shown below.

rust
fn responses_websocket_enabled() -> bool {
    if !supports_websockets {
        return false;
    }
    // additional session state check
    if session_disabled_websocket {
        return false;
    }
    true
}

Two main variables control this behaviour. The first variable supports_websockets is a global configuration flag. The second flag session_disabled_websocket marks a session-level fallback state. If WebSocket connection fails multiple times during a session, this flag will be set to true, and WebSocket will be disabled for the remainder of that session.

The most reliable way to prevent Codex from attempting WebSocket connections is to set supports_websockets = false in the configuration file. This forces responses_websocket_enabled() to return false every time, bypassing WebSocket transport entirely.

5. Solution: Disable WebSocket and Force HTTPS Streaming

The root fix is straightforward. Instead of letting Codex automatically attempt WebSocket first, manually disable WebSocket support in Codex configuration. This forces all Responses API traffic to run over HTTPS SSE streaming.

5.1 Modify config.toml

Open or create the Codex configuration file at ~/.codex/config.toml. Insert the following configuration block.

toml
model = "gpt-4o"
model_provider = "openai_http"

[model_providers.openai_http]
name = "openai_http"
base_url = "https://api.openai.com/v1"
wire_api = "responses"
supports_websockets = false

5.2 Configuration Parameter Breakdown

  1. wire_api = "responses": This keeps the client using the Responses API, without switching to the legacy Completions API. All native Responses API features remain available.
  2. supports_websockets = false: This is the critical parameter. It tells Codex that the runtime environment cannot support WebSocket. The function responses_websocket_enabled() will always return false.
  3. The provider block defines a custom provider profile that uses HTTPS streaming exclusively.

After saving the file, restart Codex fully. The client skips the WebSocket handshake attempt entirely and uses HTTPS SSE streaming immediately. The Reconnecting 1/5 to 5/5 cycle disappears.

6. Optional Environment Configuration with .env

If you need to add proxy configuration for API requests, you can create a .env file inside the ~/.codex/ directory to store environment variables.

Example content for .env:

bash
ALL_PROXY=http://127.0.0.1:7890

You can create this file directly from the terminal on Linux or macOS with the following command:

bash
echo "ALL_PROXY=http://127.0.0.1:7890" >> ~/.codex/.env

Change the proxy address and port value according to your own local proxy service.

When developers deploy custom routing layers for LLM API traffic, API gateways can simplify credential management and request orchestration. 4sapi offers a unified routing layer for model API requests, which can be integrated for teams managing multiple model endpoints.

7. Why HTTPS Streaming Remains the Preferred Fallback

Many developers prefer HTTPS SSE streaming over WebSocket for daily coding work, mainly for two practical reasons: better network compatibility and simpler observability.

7.1 Broader Network Compatibility

HTTPS SSE uses standard 443 HTTPS requests. Most firewalls, proxies and network infrastructure are built to allow HTTPS traffic. Many common AI platforms including DeepSeek, GLM and Qwen fully support SSE streaming. WebSocket support varies widely across different proxy services and network environments. In restrictive corporate or campus networks, HTTPS streaming almost always works while WebSocket may be blocked.

7.2 Simpler Debugging and Observability

HTTPS requests are easy to inspect using standard network debugging tools. Developers can view request headers, payloads, prompt content, token consumption and streaming events directly. Troubleshooting connection timeouts, rate limits and authentication failures becomes much easier without WebSocket binary framing.

8. Real-world Test Results

Before applying the configuration change:
Every new chat triggers the Reconnecting counter sequence. Users wait for multiple retry cycles before the client falls back to HTTPS streaming. The waiting period typically ranges from 10 seconds up to 40 seconds.

After editing config.toml and setting supports_websockets = false:
When sending the first message, Codex directly uses Responses API over HTTPS streaming. No WebSocket handshake attempts are made. The Reconnecting counter no longer appears on the UI. Message responses start streaming immediately after the initial request completes.

9. Conclusion

The infinite Reconnecting 5/5 loop in Codex desktop is not caused by server overload, bad API keys or model performance. The core cause is Codex’s default preference for WebSocket transport on the Responses API. When the underlying network blocks wss:// handshakes, the client repeatedly retries and increments the visible counter.

The most direct fix is modifying Codex config.toml. Set supports_websockets = false while keeping wire_api = "responses". This configuration disables WebSocket attempts and forces the client to use HTTPS SSE streaming. The Responses API capabilities are preserved, and the reconnect retry cycle is eliminated entirely.

For developers working behind restricted networks, this configuration removes the long waiting time at the start of every new conversation. The solution works reliably for daily coding workflows and agentic tasks inside Codex. Teams managing multi-model API access can leverage centralized routing tools to standardize their request pipeline.

International access: https://4sapi.com
Domestic access: https://4sapi.cn

Tags:Codex reconnecting 5/5Codex error fixCodex WebSocketHTTPS SSE streamingOpenAI Responses API

Recommended reading

Explore more frontier insights and industry know-how.