api key bach not working
What version of Codex is running?
latest
Which model were you using?
_No response_
What platform is your computer?
_No response_
What steps can reproduce the bug?
%%bash
Always grab latest Codex
npm install -g @openai/codex@latest
✅ API key authentication (fake)
export OPENAI_API_KEY="sk-proj-8Dvo0_nGTvHe6fffWX8xb5HhX5s5MHBLPlfEbc22uxKkdLs8A"
Quick smoke test (should not 401)
codex exec --full-auto --skip-git-repo-check --config preferred_auth_method="apikey" "echo Codex API auth OK"
anged 1 package in 3s
[2025-10-01T15:36:50] OpenAI Codex v0.42.0 (research preview)
--------
workdir: /content
model: gpt-5-codex
provider: openai
approval: never
sandbox: workspace-write [workdir, /tmp, $TMPDIR]
reasoning effort: none
reasoning summaries: auto
--------
[2025-10-01T15:36:50] User instructions:
echo Codex auth OK
[2025-10-01T15:36:54] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 1/5 in 208ms…
[2025-10-01T15:36:58] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 2/5 in 420ms…
[2025-10-01T15:37:02] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 3/5 in 776ms…
[2025-10-01T15:37:06] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 4/5 in 1.546s…
[2025-10-01T15:37:11] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 5/5 in 3.374s…
[2025-10-01T15:37:18] ERROR: exceeded retry limit, last status: 401 Unauthorized
[2025-10-01T15:37:18] OpenAI Codex v0.42.0 (research preview)
--------
workdir: /content
model: gpt-5-codex
provider: openai
approval: never
sandbox: workspace-write [workdir, /tmp, $TMPDIR]
reasoning effort: none
reasoning summaries: auto
--------
[2025-10-01T15:37:18] User instructions:
Extract and analyze fake made up contents. Produce an HTML report with 4 creative visualizations. Save to summary_visuals.html.
[2025-10-01T15:37:21] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 1/5 in 185ms…
[2025-10-01T15:37:25] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 2/5 in 396ms…
[2025-10-01T15:37:29] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 3/5 in 801ms…
[2025-10-01T15:37:33] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 4/5 in 1.577s…
[2025-10-01T15:37:38] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 5/5 in 3.2s…
[2025-10-01T15:37:45] ERROR: exceeded retry limit, last status: 401 Unauthorized
What is the expected behavior?
_No response_
What do you see instead?
_No response_
Additional information
_No response_
5 Comments
Getting similar issues. I think the codex authorization server is down or something.
Just to confirm, this is latest prod or alpha? Can you attach the exact version?
latest prod
The behavior you're describing can be explained by a corrupt or incorrect API Key.
I presume this bug report is stale, so I'm going to close.
I struggled this issue more than 1month.
I solved in my situation finally.
before v0.34
You can use OPENAI_API_KEY envvar (I used this version)
after v0.36
You should use
codex login --api-keycommand explicitly,after v0.46
Use
codex login --with-api-keyto follow the instruction below,https://github.com/openai/codex/blob/main/docs/authentication.md#usage-based-billing-alternative-use-an-openai-api-key