Bug when I send a first message "stream error: ..."
What version of Codex is running?
0.3.0
Which model were you using?
codex-mini-latest
What platform is your computer?
MacOS
What steps can reproduce the bug?
1 ) codex login
2 ) codex
3 ) type prompt -> enter
What is the expected behavior?
send "Hello"
Expect to get "Hello" from Codex Mini
What do you see instead?
user
say "hello"
event
BackgroundEvent(BackgroundEventEvent {
message: "stream error: stream disconnected before completion: stream closed before response.completed; retrying 1/10 in 191ms…"
})
event
BackgroundEvent(BackgroundEventEvent {
message: "stream error: stream disconnected before completion: stream closed before response.completed; retrying 2/10 in 239ms…"
})
event
BackgroundEvent(BackgroundEventEvent {
message: "stream error: stream disconnected before completion: stream closed before response.completed; retrying 3/10 in 362ms…"
})
event
BackgroundEvent(BackgroundEventEvent {
message: "stream error: stream disconnected before completion: stream closed before response.completed; retrying 4/10 in 461ms…"
})
Additional information
_No response_
65 Comments
Same problem for me.
This happened when I updates to v0.3.
node
v22.17.0ubuntu 24.04hey @dam62500 , what is your Node.js version?
@yusuf-eren node v18.16.0 on Mac ( 2019 / Intel )
Don't work too with Windows 11, node v20.18.0. ( same problem )
Same, with node v20.13.1 on mac
I tested it on v18.16.0, v20.18.3, v22.16.0. Also tried uninstalling and clean installing via
brew install codex, but still couldn't reproduce the bug.Are you using a
config.tomlfile? It should be located at~/.codex/config.tomlSee: config docs
If so, could you share its contents?
Same issue. Same version and OS
Having the same issue on MacOS / Darwin 24.3.0.
No config.toml exists, just the auth.json,
It looks like this error is actually being triggered from submission of the (initial internally-generated) API Key creation request, NOT the user specified prompt. So this probably won't occur if you are connected to an Organisation with an existing API key, I would recommend testing if the issue is reproducable from a fresh OpenAI account - perhaps at least a fresh Org.
Sample from the codex-tui.log file:
2025-07-08T18:24:14.288188Z INFO Configuring session: model=codex-mini-latest; provider=ModelProviderInfo { name: "OpenAI", base_url: "https://api.openai.com/v1", env_key: Some("OPENAI_API_KEY"), env_key_instructions: Some("Create an API key (https://platform.openai.com) and export it as an environment variable."), wire_api: Responses, query_params: None, http_headers: Some({"version": "0.3.0", "originator": "codex_cli_rs"}), env_http_headers: Some({"OpenAI-Organization": "OPENAI_ORGANIZATION", "OpenAI-Project": "OPENAI_PROJECT"}) }
2025-07-08T18:24:16.099177Z WARN stream disconnected - retrying turn (1/10 in 211ms)...
2025-07-08T18:24:17.657017Z WARN stream disconnected - retrying turn (2/10 in 276ms)...
2025-07-08T18:24:19.706377Z WARN stream disconnected - retrying turn (3/10 in 364ms)...
2025-07-08T18:24:21.013135Z WARN stream disconnected - retrying turn (4/10 in 471ms)...
2025-07-08T18:24:22.278961Z WARN stream disconnected - retrying turn (5/10 in 544ms)...
2025-07-08T18:24:23.432097Z WARN stream disconnected - retrying turn (6/10 in 808ms)...
2025-07-08T18:24:24.947856Z WARN stream disconnected - retrying turn (7/10 in 1.052s)...
2025-07-08T18:24:26.719088Z WARN stream disconnected - retrying turn (8/10 in 1.358s)...
2025-07-08T18:24:28.690865Z WARN stream disconnected - retrying turn (9/10 in 1.591s)...
2025-07-08T18:24:32.318628Z WARN stream disconnected - retrying turn (10/10 in 2.221s)...
2025-07-08T18:24:35.114276Z INFO Turn error: stream disconnected before completion: stream closed before response.completed
same here
same
I have the same issue node: v22.7.0, Ubuntu 24. I didn't have config.toml, so I created one according to the docs. This is what I have currently:
but nothing changed. It is essencially the same as gpt-4 and the codex-mini:
still unresolved?
I also get the same error. I'll show you the scenarios I tried below
same
same
I found that the following message was displayed after
codex login:Sorry, your subscription must be active for more than 7 days to redeem credits.I also encountered this issue on a newly created platform account, linking it to a longstanding ChatGPT identity. I suspect the CLI is failing on the attempt to redeem free credit on Pro/Plus accounts. Likely on the 7 day minimum account age check.
When I switched the CLI to use an older API key on another account, it started working.
Well it turns out I only needed to put something in my Organization Balance for it to work.
I tried adding money to my organization balance and this did not resolve for me.
I also generated a new key, not using
codex loginand tried settingOPENAI_API_KEYto that. It still resulted in the stream error on first prompt.I have added money to my org and it didn’t fix anything for me.
Now I can’t even spend the money I added!
Tried codex login multiple times. Tried env var. Deleted many times .codex from home dir. Nothing helps.
My issue was resolved by adding money; the error message is not informative but when I downgraded to an older version, I got a more informative one. I'm also charged for the first tokens even though I'm on a data-sharing agreement, but that's for another time.
I've been getting this issue as well. I'm not entirely sure but I think it may be due to not verifying your organization here: https://platform.openai.com/settings/organization/general. This seems to be needed to access any of OpenAI's modern models however I've used them before in other context's without having to verify so it's confusing. Personally I'm reluctant to verify (sharing photo of government ID) just for briefly testing out Codex CLI right now.
I think you're onto something there clarkio... but it seems they're using that LinkedIn spin-off that doesn't honour the nuances of regional and national differences in identity documents.... I don't have a current passport, so now I'm stuck.
A) Please just use my countries (AU in this case but it applies to all nations of the world I'm sure) well documented and maintained by the Federal Government DVS (Document Verification System). Either use localised national standards... or don't implement the ID requirement, please for the love of $DIETY_WHO_CREATED_THIS_SIMULATION...
(sure sure, you'll have to use different DVS/KYC backends for each country but like.... use CoPilot or something :P)
B) Don't Dark Pattern the UX. The workflow first made me add funds to buy some API credit, and only after that did it inform me I need to prove my ID to use them. You've taken money and immediately afterwards refused to provide a service - bad show old bean..
Verifying my organization fixed it as well
Same problem.
If you have a paid OpenAI account, run the following to start the login process:that's what they say on https://github.com/openai/codex but it seems they are trying to get you with openai API account. Hope they fix it soon.Yesterday it worked well but today this error occured.
That's a little misleading because you need to fund your Organization anyway to use the API. Right?
same here
same problem here
Have the same issue. Wanted to try it locally due i have my repo not on github.
I finally get it now. I was mistaken in thinking that a paid ChatGPT subscription would let me use the API freely. It turns out you actually have to pay for API usage on the OpenAI API Platform. It seems this error shows up when you don't have enough credits.
@NJersyHiro But then the readme is misleading. As i understand with a Plus/Pro Subscription no API credits should be needed. Readme says either set openapi token or if you have Plus/Pro use the login method.
I was using version
0.4.0, and having the same issue.After downgrading with
npm i @openai/codex@0.2.0I was able to see more detailed error messages.< _In my case_ > Even though I had OpenAI credits available, my organisation was not verified.
5 minutes after the verification process and I was able to run everything just fine.
Yes, the README is misleading.
The codex login command is intended only to provide a simpler authentication process; it doesn't mean that a Plus/Pro plan grants free or unlimited API usage.
In fact, as you can see during the authentication flow, the following message is displayed: "Codex CLI will receive a token that allows it to generate API keys and consume API credits."
Verifying Organization resolved this issue for me. Thank you @devkiloton
I'm using v
0.4.0and was experiencing the same issue. Credit to @clarkio, about 5-10 minutes after organization verification, everything was working as expected.same issue
Topping up my OpenAI Platform balance solved the immediate problem, but I’m disappointed that an unlimited Codex plan is not included in the OpenAI Pro subscription. While debugging a simple application I spent about €250+ on pay‑as‑you‑go Codex requests and eventually had to stop using the model altogether. Could you please reconsider this policy? At present Codex feels as impractical as a metered internet connection; an unlimited option—similar to what some other providers offer—would make it genuinely useful.
Same issue, 0.5.0.
Claude is cheaper and works out of the box.
What the point to log in using plus credentials if we need to buy API credits.
same issue 0.7
same issue
Same issue :(
Are any of the devs going to chime in here?
Same issue with codex-cli 0.8.0
Same issue, not working even with credits in the account
Me too
Same
I had the same issue until I find out that my credits were expired, I didn't know that the have to be used before 1 year
I'm seeing this as well.
Getting this OFTEN.
same
I am seeing this as well, on the latest version sharing my ChatGPT Plus subscription usage
same here wthelly
I updated to the latest version and I have logged in again with my chatgpt sub. Now cli works fine.
Make sure that you have gpt-5 model as the model. There might be some issue where non gpt-5 models still require an api key
I had the same issue. It was fixed after I removed some variables from my
.envfile that I had used before (OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MODEL).I also logged in with my normal account and it was fine but when I went back and used my api key I got hit with the rate limit quite frequently
this popped up a few times as well
▌ ● Working (52s • Ctrl C to interrupt) [INFO codex_tui::chatwidget] BackgroundEvent: stream error: stream disconnected before completion: stream closed beforeQuick update from my last message here...
As of today after updating to version
0.20.0I was able to successfully log in via OAuth with both a personal and work/team account without having to verify my org by sharing a government ID.For folks just catching up on this the last version I tested was <=
0.5.0. In those versions login would fail for me. After some digging into errors I found a message regarding verifying the organization associated to my account (this happened for both personal and work/team accounts). In order to do that I would have to upload/share a government ID via a third-party partner and I did not believe that should be necessary so I stopped there. Thankfully this is no longer the case.So if you've run into issues with logging in previously, try updating to the latest version (
npm i -g @openai/codex), usecodex loginand follow the OAuth flow to see if you get better results now.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.
I finally solved it!!!! 🎉
The problem was that OpenAI’s API settings were stored in the shell. Once I deleted all those values, completely removed Codex (including the .codex folder), and reinstalled it, it worked.
Instead of running codex login, just type codex to connect and log in.
How to avoid it, In my project I have the same config .env but it should not be applied for codex cli
I got errors like:
The codex version is: 0.30.0
OS: Ubuntu 24.04 in win + wsl2
We have fixed the issue with .env loading in the 0.30.
I'm going to close this issue as many problems enchanted here has been solved. Please file a new issue if things still don't work for you.