stream error: stream disconnected before completion: stream closed before response.complete; retrying...

Resolved 💬 46 comments Opened Jul 15, 2025 by FreedomLabsIO Closed Oct 16, 2025
💡 Likely answer: A maintainer (bolinfest, collaborator) responded on this thread — see the highlighted reply below.

What version of Codex is running?

codex-cli 0.7.0

Which model were you using?

codex-mini-latest

What platform is your computer?

Linux 6.8.0-63-generic x86_64 x86_64

What steps can reproduce the bug?

Send any prompt after codex login

What is the expected behavior?

Model response

What do you see instead?

<img width="1505" height="698" alt="Image" src="https://github.com/user-attachments/assets/1af1875d-3460-4f72-9c0c-85003ec0d3f3" />

Additional information

_No response_

View original on GitHub ↗

46 Comments

BedrettinOrtak · 1 year ago

same error on macos anyone help?

Qi-jsallis · 1 year ago

Same error on WSL...

Cai-z-us · 1 year ago

Same error on WSL...

BedrettinOrtak · 1 year ago

Will anyone take care of this problem?

nicolas-san · 1 year ago

+1

pwnz22 · 1 year ago
  • same problem
polcrub · 1 year ago

same issue in macOS with azure APIs

youvalv · 1 year ago

same issue version 0.7

Cai-z-us · 1 year ago

@bolinfest

markuskreitzer · 1 year ago

After endless searching and experimenting, I got past this issue. I don't think it's as much Codex's fault as the transition going on at Azure right now. I went to Azure AI Foundry and pieced together this config that works with codex with plain ol' gpt-4o.

model_provider = "azure"
provider = "azure"
model = "<deployment name>" # Your deployment name, not the ai model name.

# This From AI Foundry:
# https://<your resource>.openai.azure.us/openai/deployments/<deployment name>/chat/completions?api-version=2025-01-01-preview

[model_providers.azure]
name         = "Azure OpenAI" # Not certain if this name matters.
base_url     = "https://<resource>.openai.azure.us/openai/deployments/<deployment name>"
env_key      = "AZURE_OPENAI_API_KEY"
#wire_api     = "responses" # Don't think this works with GPT-4o
query_params = { api-version = "2025-01-01-preview" } # Get this from AI Foundry URL. Azure AI Services had the wrong version, which sent me down the wrong path for half a day.

I have tested this with the latest npm version (0.7.0)

xHeaven · 1 year ago

Just to clarify, do you have any amount of money topped up to your credit? Check it here: https://platform.openai.com/settings/organization/billing/overview
I had the same issue, but as soon as I topped up my balance with $5, the error message is gone. Even though I have/had $38 in credit grants.

BedrettinOrtak · 1 year ago

ı have 120$ but not working

polcrub · 1 year ago

I have an Azure student license for context. The only configuration that does something for me is:

# Default settings ── used when you run plain `codex`
model_provider  = "azure"
provider        = "azure"
model           = "o4-mini"            # pick whatever you want as your day-to-day default

[model_providers.azure]
name         = "Azure OpenAI"
# NOTE: leave **only** the part up to /openai
base_url    = "https://<resource>.cognitiveservices.azure.com/openai"
env_key      = "AZURE_OPENAI_API_KEY"        
wire_api     = "responses"                   
query_params = { api-version = "2025-04-01-preview" }

Where my "resource" name is the "folder" with multiple models deployed, I did not find a way to access an individual deployed model. Moreover, any other api-version fails. With this configuration o3-mini seems to work for more than one message (o4-mini always fails after the first response, always). see:

<img width="542" height="377" alt="Image" src="https://github.com/user-attachments/assets/871666cc-146c-4a67-aa37-9aa871d4ef31" />

With o4-mini:

<img width="828" height="402" alt="Image" src="https://github.com/user-attachments/assets/08105b18-a9cd-4149-a702-06c95cd0e40c" />

The set up it's just too messy. I'm working with the 0.7.0 version installed via brew.

polcrub · 1 year ago
https://grok.com/share/bGVnYWN5_291468fe-b9cd-44a4-928e-dbc5be3b4542

I did build the latest main branch up until now, the codex cli interface is different (OpenAI Codex (research preview) v0.0.0-dev ). And now nothing works with the config I shared before, which I had to convert to JSON since for some reason the .toml version is ignored. See:

<img width="1126" height="402" alt="Image" src="https://github.com/user-attachments/assets/20b8acb0-3a70-4e7b-930d-7bded9485f9c" />

At least it loads faster and you can try more messages once past the error. I'm giving up.

doroness · 1 year ago

<img width="960" height="564" alt="Image" src="https://github.com/user-attachments/assets/e9f474cf-2fd0-4053-bba6-089eb2ebf0ad" />

Same for me

sjdefalco · 12 months ago

Same error as everyone above. I have $ in my api credit.

when I logged in initially I got:

Credit redemption request failed: HTTP Error 400: Bad Request
Successfully logged in

netpoetica · 12 months ago

For me, if I use the default model it works just fine, but if I update config.toml to have model = "o3" then I receive this error endlessly. Similarly, if I launch with codex -m o3, will get the same error. It seems specific to using o3 for me. I have a Plus subscription so I wouldn't expect there to be an issue with credits, etc.

fnavarijo · 12 months ago

For me ocurred the same when using the models: codex-mini-latest and o4-mini.
But when using o3-mini it started working. Is codex cli limited to specific models for the moment?

netpoetica · 12 months ago

As a small update - I found that after I went through Verification in my Organization (using third party Persona svc) I was able to use o3 via codex/cli for quite some time (hours). I did however once again just start observing the same issue consistently, 3 or 4 retries resulting in BackgroundEvent { message: "stream error: stream disconnected before completion..." }

sjdefalco · 12 months ago

Ok I seem to have fixed this. You need to be verified before you can use the default model. I was able to get it working as-is by running codex -m o3-mini.

To use the other models, in the Logs section from the Dashboard (https://platform.openai.com/logs) if you click into one of the failed messages and scroll all the way to the bottom, it will tell you that you need to be verified to use certain models.

You can complete that process here: https://platform.openai.com/settings/organization/general

Once that was done, I can now use the default model codex-mini-latest (and I believe a few others you need verification for).

daniel-heater-imprivata · 12 months ago

-m o3-mini didn't work for me with 0.8.0 on MacOS. I installed codex with brew

A colleague shared that they installed with npm install -g @openai/codex@native earlier and did not get the stream error. The same for me. No stream error (still need company to fund before I can test it). But npm install -g @openai/codex@native shows the version as codex-cli 0.0.2505291458

HunterHillegas · 11 months ago

I'm seeing this as well.

  • macOS 26 beta 4
  • Codex CLI v0.10
  • Multiple models: o3, codex-mini-latest
  • Organization has been long verified
  • Plenty of budget in the account

Still, tons of these stream errors.

lukaszciastko · 11 months ago

Same here. I wanted to use codex but seeing these errors instead.

QualityRobD · 11 months ago

Yep same in WSL. Using an enterprise account but aside from that it's setup the same.

v0.20.0 as well, so the latest available version.

  1. I can auth into the CLI but any calls are met wtih that streaming error.
  2. Our organization is verfified so it's not that the issue
yasuda0320 · 11 months ago

This is about my mistake—I had specified the following in my .env file for Qwen Code. The OPENAI_BASE_URL setting here was affecting Codex CLI and causing the error "🖐 stream disconnected before completion: stream closed before response.completed." Maybe you could check your environment variables or the contents of your .env file?

OPENAI_API_KEY=sk-or-v1-xxxxxxxxxx
OPENAI_BASE_URL=https://openrouter.ai/api/v1
OPENAI_MODEL=qwen/qwen3-coder:free

grahamseamans · 11 months ago

Fixed it by removing open-ai related environment variables in my zsh rc. I'm guessing that codex defaults to bash env vars over what you set set in the actual codex config. IDK why it would be this way, but this did fix it for me.

landmann · 10 months ago

I'm getting this now every 5-10 minutes. Something broke in the last update.

i-oliva · 10 months ago

Getting this every few minutes...

bolinfest collaborator · 10 months ago

This may be because we stopped honoring .env in 0.30.0? See "breaking changes:"

https://github.com/openai/codex/releases/tag/rust-v0.30.0

/cc @pakrym-oai

soLorden · 10 months ago

getting same error all the time. any fix?

Adamcf123 · 10 months ago

Same error. almost unusable

vnicolici · 10 months ago

I started getting this error today in a long session that worked fine yesterday. It seems to work fine if I start a new session. I'm guessing the model I was using during that session, apparently gpt-5-1p-codexswic, is not available anymore?

The model from /status looks the same in both the old and the new session that works:

🧠 Model
• Name: gpt-5
• Provider: OpenAI
• Reasoning Effort: Medium
• Reasoning Summaries: Auto

But I'm guessing the version of the model I was using in the old session has been retired while I was working. These are the errors I get in the old session:

✔ You approved codex to run go build ./... this time

_

✗ ⌨️ go build ./...
error: command timed out
⚠  stream error: stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found; retrying 1/5 in 200ms…

⚠  stream error: stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found; retrying 2/5 in 394ms…

⚠  stream error: stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found; retrying 3/5 in 865ms…

⚠  stream error: stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found; retrying 4/5 in 1.628s…

⚠  stream error: stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found; retrying 5/5 in 3.306s…

🖐  stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found

user
It seems there were some inference API error when you attempted to build. Can you try again?
⚠  stream error: stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found; retrying 1/5 in 190ms…

⚠  stream error: stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found; retrying 2/5 in 408ms…

⚠  stream error: stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found; retrying 3/5 in 731ms…

⚠  stream error: stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found; retrying 4/5 in 1.759s…

⚠  stream error: stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found; retrying 5/5 in 3.334s…

🖐  stream disconnected before completion: Attempted an engine lookup because both a model and engine were passed. Engine gpt-5-1p-codexswic not found

▌ Write tests for @filename
⏎ send Ctrl+J newline Ctrl+T transcript Ctrl+C quit 513323 tokens used 80% context left

raulblanko · 10 months ago

similar issue, the error today in a long session that worked fine since yesterday until this moment:

• Ran powershell -NoProfile -Command 'npm run typecheck'                        
                                                                                
⚠️ stream error: stream disconnected before completion: Transport error: error  
decoding response body; retrying 1/5 in 186ms…                                  
                                                                                
⚠️ stream error: stream disconnected before completion: Transport error: error  
decoding response body; retrying 2/5 in 402ms…                                  
                                                                                
⚠️ stream error: stream disconnected before completion: Transport error: error  
decoding response body; retrying 3/5 in 772ms…                                  
                                                                                
⚠️ stream error: stream disconnected before completion: Transport error: error  
decoding response body; retrying 4/5 in 1.575s…                                 
                                                                                
⚠️ stream error: stream disconnected before completion: Transport error: error  
decoding response body; retrying 5/5 in 3.371s…                                 
                                                                                
🖐  stream disconnected before completion: Transport error: error decoding       
response body                                                                   
                                                                                
▌ Implement {feature}                                                           
 ⏎ send   Ctrl+J newline   Ctrl+T transcript   Ctrl+C quit   2.52M tokens used

is it possible that too many tokens used (2.52M in my case) is a reason?

also could anyone please help with arguments to be passed to the command line to continue the old session? is it possible?

vnicolici · 10 months ago
also could anyone please help with arguments to be passed to the command line to continue the old session? is it possible?

It is possible if you are on codex cli 0.30.0 or newer, the options are --resume and --continue. They are not documented in --help at the moment.

https://github.com/openai/codex/issues/2173#issuecomment-3264145154

Unfortunately it doesn't support resuming sessions created with older versions. As a workaround, I copied the json. session file from the .codex directory to the project I was working on, then, in a new session, I asked it to read it to familiarize itself with the previously done work. That worked reasonably well.

raulblanko · 10 months ago

@vnicolici

I copied the json. session file from the .codex directory to the project I was working on, then, in a new session, I asked it to read it to familiarize itself

Almost like i did before, but even without a copying. It has access to its home directory.

the options are --resume and --continue. They are not documented in --help at the moment.

Huge thanks for that!

yonson40 · 10 months ago

I get the same error for both codex ide and codex cli but only on my macbook, not when im on windows parallels, or on my mac mini... Super annoying...

aud · 10 months ago

FWIW this makes Codex completely unusable. Surprised this is still open. I have an OPENAI_API_KEY set in my env. Should be considered a sev0.

aibrahim-oai contributor · 10 months ago

As of 0.36, we don't support implicit login. You need to use codex login --api-key "your-api-key-here" to explicitly login using your api key.

Release notes

aud · 10 months ago

@aibrahim-oai Thanks. This error should really be handled properly. For eg. the stream error should propagate some status code code so people can at least see it's failing for authentication reasons.

Or, better yet perform some sort of pre-flight check when you launch Codex that verifies that you have authentication configured properly, and if not guides you to do the right thing.

evanreilly · 10 months ago

▌ Write tests for @filename
⏎ send Shift+⏎ newline Ctrl+C quit`@aib

As of 0.36, we don't support implicit login. You need to use codex login --api-key "your-api-key-here" to explicitly login using your api key. Release notes

`codex login --api-key
"<redacted>"
Successfully logged in
(base) evanreilly@Evans-MacBook-Pro-2 moondream-station % codex
✨⬆️ Update available! 0.23.0 -> 0.38.0.
Run npm install -g @openai/codex@latest to update.

_ You are using OpenAI Codex in ~/code/moondream/moondream-station

To get started, describe a task or try one of these commands:

/init - create an AGENTS.md file with instructions for Codex
/status - show current session configuration and token usage
/diff - show git diff (including untracked files)

user
walk me through converting this to mlx

🖐 stream disconnected before completion: stream closed before response.completed

care to explain @aibrahim-oai ?

evanreilly · 10 months ago

at my wits end, upgraded npm, upgraded codex, signed in with oauth, signed in with api key. Still always get

🖐 stream disconnected before completion: stream closed before response.completed

evanreilly · 10 months ago

also same deal with vscode/cursor extensions

Prestapro · 9 months ago

I'm not sure it's work for you, but it's work for me twice (Mac OS 26, M2 Max). If any member or developer from team Open AI/Codex, please check this issue. I think it's authoriztion/key. I attach additional information (describe problem)[/+]

name:

"🐞 Codex CLI Bugfix / Diagnostic Checklist"

about:

Fix or diagnose stream disconnects / 401 errors in codex-cli v0.43.x

title:

"[Bug] Codex CLI stream disconnect or 401 Unauthorized"

labels:

["bug", "codex-cli", "openai-cli"]

assignees: ""

🧩 Codex CLI Bugfix / Diagnostic Checklist

Target: macOS ARM — codex-cli v0.43.0-alpha.15
Purpose: Fix or diagnose stream disconnect or 401 Unauthorized issues during ChatGPT SSO sessions.

---

A) Clean Environment Variables

env | egrep -i 'OPENAI|OPENROUTER|AZURE'
unset OPENAI_API_KEY OPENROUTER_API_KEY AZURE_OPENAI_API_KEY

---

B) Login via ChatGPT SSO

(officially recommended for Plus / Pro / Team users)

codex login
In the browser window, choose Sign in with ChatGPT → confirm.

---

C) Launch TUI and Check Status

codex

Inside the TUI:

/status

---

D) Switch Model to Stable gpt-5

/model

Select gpt-5 (not gpt-5-codex).

---

E) Quick Sanity Stream Test

Say "pong" and nothing else.
Expect a clean streamed response with no disconnection.

If OK — switch back to gpt-5-codex and repeat.

---

🪲 If the stream disconnects

Enable Debug Logging

RUST_LOG=debug codex

In another terminal:

tail -F ~/.codex/log/codex-tui.log

---

✅ Minimal Fix — Force Stable Model

Option 1 — One-off Launch

codex --model gpt-5

Option 2 — Make Default

mkdir -p ~/.codex
printf 'model="gpt-5"\n' > ~/.codex/config.toml
codex

Then check inside TUI:

/status
Should show: Model: gpt-5

---

If the stream still breaks

1️⃣ Relogin and Clear Cache

codex logout
rm -rf ~/.codex ~/.config/codex
codex login

2️⃣ Recreate Minimal Config

mkdir -p ~/.codex
printf 'model="gpt-5"\n' > ~/.codex/config.toml

3️⃣ Start with Debug Logs

RUST_LOG=debug codex

In another terminal:

tail -F ~/.codex/log/codex-tui.log

4️⃣ Verify SSE Network Stability

curl -N https://stream.wikimedia.org/v2/stream/recentchange
If this also disconnects — the issue is with local network, proxy, or SSL interception.

5️⃣ Headless Mode (Non-TUI)

codex exec "Say 'pong' and stop."
If this works but TUI fails → it’s a TUI stream issue.

---

🔧 Clean Up OpenRouter / BASE URL / Proxy

env | egrep -i 'OPENROUTER|ROUTER|OPENAI.*BASE|API_BASE|BASE_URL|PROXY'
unset OPENROUTER_API_KEY OPENROUTER BASE_URL OPENAI_BASE_URL OPENAI_API_BASE HTTPS_PROXY HTTP_PROXY ALL_PROXY NO_PROXY
sed -i.bak '/OPENROUTER\|OPENAI_.*BASE\|API_BASE\|BASE_URL\|_PROXY/d' ~/.zshrc ~/.bashrc ~/.bash_profile 2>/dev/null
grep -RIn --no-ignore -E 'openrouter\.ai|OPENROUTER|OPENAI_.*BASE|API_BASE|BASE_URL' ~ 2>/dev/null | head -n 50
rm -rf ~/.codex ~/.config/codex
mkdir -p ~/.codex && printf 'model="gpt-5"\n' > ~/.codex/config.toml
export OPENAI_BASE_URL="https://api.openai.com/v1"
RUST_LOG=debug codex

Then check where Codex connects:

tail -F ~/.codex/log/codex-tui.log | egrep -i 'api\.openai\.com|openrouter\.ai|api_request'
Should show api.openai.com (not openrouter.ai).

---

🔐 If 401 Unauthorized Persists

A) Clean SSO Relogin

codex logout
rm -rf ~/.codex ~/.config/codex
open "https://chat.openai.com/auth/logout"
open "https://platform.openai.com/logout"
codex login
mkdir -p ~/.codex && printf 'model="gpt-5"\n' > ~/.codex/config.toml
RUST_LOG=debug codex

B) Clear Auth-Related Environment Vars

env | egrep -i 'OPENAI_(ORGANIZATION|PROJECT|API_KEY)|OPENROUTER|API_BASE|BASE_URL|_PROXY'
unset OPENAI_ORGANIZATION OPENAI_PROJECT OPENAI_API_KEY OPENROUTER_API_KEY OPENAI_BASE_URL API_BASE BASE_URL HTTPS_PROXY HTTP_PROXY ALL_PROXY NO_PROXY

C) Sync System Time (Critical for OAuth/JWT)

systemsetup -getusingnetworktime
sudo systemsetup -setusingnetworktime on
sudo sntp -sS time.apple.com

---

🧭 Temporary Workaround — API Key Mode

If SSO remains broken:

codex logout
codex login
# Choose "Use OpenAI API key"
codex --model gpt-4o
Note: ChatGPT subscription ≠ API access — use a valid sk-... key from platform.openai.com.

---

⚙️ Minimal Config Options

Simple

printf 'model="gpt-5"\n' > ~/.codex/config.toml

Explicit Provider Definition

printf '%s\n' 'model = "gpt-5"' 'model_provider = "openai"' '[model_providers.openai]' 'name = "OpenAI"' 'wire_api = "responses"' 'base_url = "https://api.openai.com/v1"' > ~/.codex/config.toml

---

✅ Expected /status Output

Model: gpt-5
Provider: openai
Wire API: responses

---

Please attach:

  • the last 20 lines from ~/.codex/log/codex-tui.log near the failure,
  • /status output from inside the TUI.

Maintainers will review logs to determine if the issue is SSO, SSE, or model access related.

---

Prestapro · 9 months ago

<html>
<head>

</head>
<body>

<p class="p1">The root cause of this <span class="s1"><b>Codex CLI bug</b></span> isn’t just “one thing” — it’s a <span class="s1"><b>combination of authentication and environment misalignment</b></span> introduced in the 0.41–0.43 branch.</p>
<p class="p1">Here’s a clear technical breakdown 👇</p>
<p class="p2"><span class="s2"><hr></span></p>
<p class="p2"><span class="s2"><h2><b>🔍 Root Cause Summary</b></h2></span></p>
<p class="p3"><br></p>
<p class="p1">Codex CLI (<span class="s3">codex-cli 0.43.x</span>) uses multiple authentication and networking backends — <span class="s1"><b>ChatGPT SSO</b></span>, <span class="s1"><b>OpenAI API key</b></span>, and <span class="s1"><b>OpenRouter</b></span> routing.</p>
<p class="p4"><span class="s4">When these collide or get misdetected, the CLI </span><b>sends requests to the wrong API endpoint or with invalid tokens</b><span class="s4">, leading to:</span></p>
<p class="p2"><span class="s2"><ul><li>
<p class="p1">401 Unauthorized<span class="s1"> errors</span></p>
</li><li>
<p class="p1">Broken <span class="s1"><b>SSE (Server-Sent Events)</b></span> streams in TUI mode</p>
</li><li>
<p class="p1">Sudden disconnects when using models like <span class="s1">gpt-5-codex</span></p>
</li></ul></span></p>
<p class="p2"><span class="s2"><hr></span></p>
<p class="p2"><span class="s2"><h2><b>⚙️ Detailed Breakdown</b></h2></span></p>
<p class="p3"><br></p>
<p class="p2"><span class="s2"><h3><b>1.<span class="Apple-converted-space"> </span></b></h3><h3><b>SSO Token Mismatch</b></h3></span></p>
<p class="p2"><span class="s2"><ul><li>
<p class="p1">The “Sign in with ChatGPT” SSO flow issues a <span class="s1"><b>short-lived JWT</b></span> token, valid only for ChatGPT web context.</p>
</li><li>
<p class="p1">Codex CLI, however, sometimes tries to reuse it for <span class="s1"><b>OpenAI’s API endpoints (api.openai.com/v1/responses)</b></span> — which reject it with <span class="s2">401 Unauthorized</span>.</p>
</li><li>
<p class="p1">This happens because CLI doesn’t refresh the SSO token correctly or misidentifies the provider.</p>
</li></ul></span></p>
<p class="p3"><br></p>
<p class="p4"><b>Symptoms:</b><b></b></p>
<p class="p2"><span class="s2"><ul><li>
<p class="p1"><span class="s1">/status</span> shows “Logged in with ChatGPT” but every call to OpenAI fails.</p>
</li><li>
<p class="p1"><span class="s1">codex.api_request</span> lines in logs return <span class="s1">401</span> even though login appears successful.</p>
</li></ul></span></p>
<p class="p2"><span class="s2"><hr></span></p>
<p class="p2"><span class="s2"><h3><b>2.<span class="Apple-converted-space"> </span></b></h3><h3><b>Conflicting Environment Variables</b></h3></span></p>
<p class="p3"><br></p>
<p class="p1">Many users have legacy or hidden exports like:</p>

<pre><code>OPENAI_API_KEY
OPENAI_BASE_URL
OPENROUTER_API_KEY
API_BASE
BASE_URL</code></pre>

<p class="p1">If any of these are set, Codex overrides its SSO provider logic and starts routing via:</p>
<p class="p2"><span class="s1"><ul><li>
<p class="p1"><span class="s1">openrouter.ai</span> (proxy endpoint)</p>
</li><li>
<p class="p1">or a stale custom <span class="s1">OPENAI_BASE_URL</span></p>
</li></ul></span></p>
<p class="p3"><br></p>
<p class="p1">Result:</p>
<p class="p1">SSO token is valid, but requests go to the wrong host → instant disconnection or 401.</p>
<p class="p2"><span class="s1"><hr></span></p>
<p class="p2"><span class="s1"><h3><b>3.<span class="Apple-converted-space"> </span></b></h3><h3><b>Model Access Policy Change</b></h3></span></p>
<p class="p2"><span class="s1"><ul><li>
<p class="p1"><span class="s1">gpt-5-codex</span><span class="s2"> sometimes requires </span><b>org-level verification</b><span class="s2">.</span></p>
</li><li>
<p class="p1">Normal <span class="s1">gpt-5</span> is public for Plus/Pro/Team SSO users.</p>
</li><li>
<p class="p1">So the same token can succeed with <span class="s1">gpt-5</span>, but fail with <span class="s1">gpt-5-codex</span>.</p>
</li></ul></span></p>
<p class="p3"><br></p>
<p class="p1">This causes false reports of “streaming broken,” while the real issue is <span class="s2"><b>permission denial</b></span> on that specific model.</p>
<p class="p2"><span class="s1"><hr></span></p>
<p class="p2"><span class="s1"><h3><b>4.<span class="Apple-converted-space"> </span></b></h3><h3><b>TUI Stream (SSE) Regression</b></h3></span></p>
<p class="p3"><br></p>
<p class="p1">Versions <span class="s3">0.41–0.42</span> had partial regressions in the SSE handler:</p>
<p class="p1">the <span class="s2"><b>event parser</b></span> and <span class="s2"><b>connection timeout</b></span> were not robust to partial chunked responses.</p>
<p class="p1">So even when the model response was valid, the client aborted early.</p>
<p class="p3"><br></p>
<p class="p1">That’s why:</p>
<p class="p2"><span class="s1"><ul><li>
<p class="p1"><span class="s1">codex exec "Say 'pong'"</span> (headless mode) works perfectly,</p>
</li><li>
<p class="p1">but <span class="s1">codex</span> (interactive TUI) drops mid-stream.</p>
</li></ul></span></p>
<p class="p2"><span class="s1"><hr></span></p>
<p class="p2"><span class="s1"><h3><b>5.<span class="Apple-converted-space"> </span></b></h3><h3><b>Network Layer / SSL Inspection</b></h3></span></p>
<p class="p3"><br></p>
<p class="p1">When all else is correct, some macOS setups still interrupt streaming:</p>
<p class="p2"><span class="s1"><ul><li>
<p class="p1">HTTPS interception (AdGuard, Little Snitch, antiviruses)</p>
</li><li>
<p class="p1">Corporate proxy rewriting chunked transfer encoding</p>
</li><li>
<p class="p1">Broken SSE keep-alive frames</p>
</li></ul></span></p>
<p class="p3"><br></p>
<p class="p1">You can confirm by:</p>

<pre><code>curl -N https://stream.wikimedia.org/v2/stream/recentchange</code></pre>

<p class="p1">If that stream also dies → it’s the network layer, not Codex.</p>
<p class="p2"><span class="s1"><hr></span></p>
<p class="p2"><span class="s1"><h2><b>🧩 So in short</b></h2></span></p>

Category | Root Cause | Fix
-- | -- | --
Auth | ChatGPT SSO token used on API endpoint | Full relogin + remove stale auth.json
Routing | Wrong base URL (OpenRouter / proxy) | Clear env vars & config
Model | Restricted gpt-5-codex | Temporarily use gpt-5
Client | SSE parser bug in TUI | Use codex exec (headless)
Network | Proxy / SSL inspection | Test SSE with curl; disable filters

<p class="p1"><span class="s1"><hr></span></p>
<p class="p1"><span class="s1"><h3><b>✅ Confirmed Workarounds</b></h3></span></p>
<p class="p1"><span class="s1"><ol start="1"><li>
<p class="p1"><b>Hard-reset login:</b></p>
</li></ol></span></p>

<pre><code>codex logout
rm -rf ~/.codex ~/.config/codex
codex login</code></pre>

<p class="p1"><span class="s1"><ol start="1"><li>
<p class="p1">→ choose “Sign in with ChatGPT”.</p>
</li><li>
<p class="p1"><b>Force base model and endpoint:</b></p>
</li></ol></span></p>

<pre><code>mkdir -p ~/.codex
printf &#39;model=&quot;gpt-5&quot;\n&#39; &gt; ~/.codex/config.toml
export OPENAI_BASE_URL=&quot;https://api.openai.com/v1&quot;
codex --model gpt-5</code></pre>

<p class="p1"><span class="s1"><ol start="2"><li>
<p class="p1"><br></p>
</li><li>
<p class="p1"><b>If still 401:</b><b></b></p>
<p class="p2">Use API key auth instead of SSO (temporary fallback):</p>
</li></ol></span></p>

<pre><code>codex login

choose “Use OpenAI API key”

codex --model gpt-4o</code></pre>

<p class="p1"><br></p>
<p class="p2"><span class="s1"><hr></span></p>

</body>
</html>

tibo-openai collaborator · 9 months ago

Please use

printenv OPENAI_API_KEY | codex login --with-api-key

and then

codex -m codex-mini-latest