You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stream error: exceeded retry limit, last status: 401 Unauthorized #2896
I had Claude diagnose the problem, it turns out that while /status showed that I was logged in, the credentials had expired, so you need to log-in again.
This should be fixed! I logged in with my ChatGPT account, but the .env file was used for application/project development. It shouldn’t automatically use it, as it consumes my application/project token.
At the very least, it should notify me that I’m using the API key instead of my ChatGPT account. Alternatively, it could simply give me a choice at the start-up.
Reacted by Daniel Duma, PhD, Michael Marvive, Sergey Tyurin and rwestwood-rondo
Same issue here, connected Codex via ChatGPT account but getting 401.
I had no .env in my workspace, but I was still exporting OPENAI_API_KEY in ~/.zprofile. Removing the export solved the issue.
In this case, it definitely shouldn't use the OPENAI_API_KEY, given I signed in using the ChatGPT account.
@diegochine What version of the CLI are you using? The latest version of the CLI is 0.29. Codex will ask you if you want chatgpt/api key login if you have an api key set on first launch.
@gpeal I'm on 0.29. I did get that question when I first launched codex and chose ChatGPT sign in. Still It just didn't work until I manually unset the OPENAI_API_KEY.
For context, I just set it again and codex is working fine now, so it probably just messed up during setup somehow.
Just come across this myself, using OPENAI_API_KEY in my .env for the application, and getting the issue with codex trying to use this, even when I have the Pro subscription.
`⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 1/5 in 201ms…
⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 2/5 in 372ms…
⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 3/5 in 859ms…
⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 4/5 in 1.561s…
⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 5/5 in 3.112s…
🖐 exceeded retry limit, last status: 401 Unauthorized
Verify that your API key is working.
setx OPENAI_API_KEY
(dont add quotes to the API key)
echo %OPENAI_API_KEY%
codex
Select:
2. Continue using API key
Pay for what you use
"codex logout", then "codex" in terminal and now works.
this worked for me as of 8th october 2025. When i typed /status it showed that i was logged in as normal but kept receiving 401 request error. I logged out in the cli then retyped codex. Once in it prompted me to use either my pro account or api key and now all cylinders are firing.
I had the same issue. In my case, the issue was resolved by executing the /logout command once and then /login via the browser. Another possible cause could simply be that the authentication session had expired.
still having this issue in 0.47.
and it seems to have something to do with projects path 'cause while some of my projects works normally, other reconnects all the time
if you are logged in, codex logout to restart unauthorized session
then run codex to create session
now if it success, you choose second login option using API key, it will fill API key automatically. And now after your codex should working and authorized.
I don't know why such openai/codex can have this silly bug look like my custom gemini-llm-cli. they probably vibe code it lol.
Reacted by Farrel Nikoson, Marco Brakmann and farrelnikoson
I experienced the same issue.
In my case, I was logged in to ChatGPT through OAuth using the VSCode extension, not an API key.
After selecting “Log out” from the extension and logging in again, it started working normally.
"Error: exceeded retry limit, last status: 401 Unauthorized, request id: ”
I used codex cli in IntelliJ IDEA on a Windows operating system this afternoon. After asking a question, I got the above error message. Code 401 is caused by Invalid Authentication, so I found the folder named ".codex", which is under the path of "C:\Users\user.codex". And the folder contains the information of key and token. Because I activated the GPT Plus service, and used codex cli by logging into my GPT account, so I simply deleted the entire folder. Then, I entered the command "codex login" , and reconfigured the command information.
If you use codex cli by key, maybe you should modify the key of "auth.json" file.
Activity
[-]codex CLI keeps saying unauthorized[/-][+]stream error: exceeded retry limit, last status: 401 Unauthorized[/+]rahulkarajgikar commentedon Aug 29, 2025
found the bug:
it was because
.envin my repository was configured to an invalid keyit was unclear because there were no logs and no clear way to debug this, echo $OPENAI_API_KEY was showing the correct key
once i fixed the key in my .env, it worked fine
migueldeicaza commentedon Aug 30, 2025
I had Claude diagnose the problem, it turns out that while /status showed that I was logged in, the credentials had expired, so you need to log-in again.
acgxv commentedon Sep 2, 2025
This should be fixed! I logged in with my ChatGPT account, but the
.envfile was used for application/project development. It shouldn’t automatically use it, as it consumes my application/project token.At the very least, it should notify me that I’m using the API key instead of my ChatGPT account. Alternatively, it could simply give me a choice at the start-up.
rahulkarajgikar commentedon Sep 2, 2025
I agree it shouldn't use .env and should use configured environment variable instead
migueldeicaza commentedon Sep 2, 2025
At least /status should display "Hey, I am getting my config from here"
diegochine commentedon Sep 3, 2025
Same issue here, connected Codex via ChatGPT account but getting 401.
I had no
.envin my workspace, but I was still exportingOPENAI_API_KEYin~/.zprofile. Removing the export solved the issue.In this case, it definitely shouldn't use the
OPENAI_API_KEY, given I signed in using the ChatGPT account.gpeal commentedon Sep 3, 2025
@diegochine What version of the CLI are you using? The latest version of the CLI is 0.29. Codex will ask you if you want chatgpt/api key login if you have an api key set on first launch.
diegochine commentedon Sep 4, 2025
@gpeal I'm on 0.29. I did get that question when I first launched codex and chose ChatGPT sign in. Still It just didn't work until I manually unset the
OPENAI_API_KEY.For context, I just set it again and codex is working fine now, so it probably just messed up during setup somehow.
RazeBerry commentedon Sep 4, 2025
Same problem here!! Very bizarre and I am using it with Pro subscription!!
mattw-services commentedon Sep 6, 2025
Just come across this myself, using OPENAI_API_KEY in my .env for the application, and getting the issue with codex trying to use this, even when I have the Pro subscription.
`⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 1/5 in 201ms…
🖐 exceeded retry limit, last status: 401 Unauthorized
/status
📂 Workspace
• Path: ~/Coding/linux-audit
• Approval Mode: on-request
• Sandbox: workspace-write
• AGENTS files: (none)
👤 Account
• Signed in with ChatGPT`
passingby000 commentedon Sep 7, 2025
same problem with codex-cli 0.30.0 when trying to use my subscription.
i've tried cli, vscode and windsurf.
hegdeguruprasad commentedon Sep 7, 2025
Solution for using API Key (Windows)
Verify that your API key is working.
setx OPENAI_API_KEY
(dont add quotes to the API key)
echo %OPENAI_API_KEY%
codex
Select:
2. Continue using API key
Pay for what you use
You should not get that error anymore
10 remaining items
frixaco commentedon Oct 2, 2025
I had the same issue (WSL2/Arch):
The issue disappeared after
/logoutand adding the API key to my env.luislobo commentedon Oct 3, 2025
I had to delete
~/.codex/auth.jsontoday for it to workML-Marco commentedon Oct 7, 2025
It doesn't work with the current version (0.45.0). I tried this:
Fails with above 401 error.
PeterP22 commentedon Oct 7, 2025
this worked for me as of 8th october 2025. When i typed /status it showed that i was logged in as normal but kept receiving 401 request error. I logged out in the cli then retyped codex. Once in it prompted me to use either my pro account or api key and now all cylinders are firing.
therzv commentedon Oct 8, 2025
try all the things above and not work, the only way to solve this issue to me is:
put OPENAI_API_KEY on .bashrc
then login like:
$ printenv OPENAI_API_KEY | codex login --with-api-key
done, smooth
DavidLee528 commentedon Oct 12, 2025
@openai/[email protected]- Issue solved by re-login:codex logout codex loginvedantdere commentedon Oct 12, 2025
Updating VS Code fixed this issue
chans97 commentedon Oct 19, 2025
That seems to be the most reliable solution.
fallonou1999 commentedon Oct 19, 2025
still having this issue in 0.47.
and it seems to have something to do with projects path 'cause while some of my projects works normally, other reconnects all the time
VArtzy commentedon Oct 21, 2025
I face the same issue
I use codex 0.47 (macOS or Linux), fix it with:
export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>codex logoutto restart unauthorized sessioncodexto create sessionnow if it success, you choose second login option using API key, it will fill API key automatically. And now after your codex should working and authorized.
I don't know why such openai/codex can have this silly bug look like my custom gemini-llm-cli. they probably vibe code it lol.
SSugar310 commentedon Oct 22, 2025
I experienced the same issue.
In my case, I was logged in to ChatGPT through OAuth using the VSCode extension, not an API key.
After selecting “Log out” from the extension and logging in again, it started working normally.
2u35eeee commentedon Oct 26, 2025
my version is OpenAI Codex (v0.50.0) and occurs exceeded retry limit, last status: 401 Unauthorized,
200105060414pys commentedon Oct 30, 2025
"Error: exceeded retry limit, last status: 401 Unauthorized, request id: ”
I used codex cli in IntelliJ IDEA on a Windows operating system this afternoon. After asking a question, I got the above error message. Code 401 is caused by Invalid Authentication, so I found the folder named ".codex", which is under the path of "C:\Users\user.codex". And the folder contains the information of key and token. Because I activated the GPT Plus service, and used codex cli by logging into my GPT account, so I simply deleted the entire folder. Then, I entered the command "codex login" , and reconfigured the command information.
If you use codex cli by key, maybe you should modify the key of "auth.json" file.
binarybana commentedon Nov 3, 2025
I found I had to generate a new API key to get codex to work. The length of the new one was significantly longer than my API key that was failing.
joker123-wpx commentedon Jan 6, 2026
牛逼兄弟,我看了半天,直接用你的成了