api key bach not working

Resolved 💬 5 comments Opened Oct 1, 2025 by firmai Closed Dec 10, 2025
💡 Likely answer: A maintainer (dedrisian-oai, contributor) responded on this thread — see the highlighted reply below.

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_

View original on GitHub ↗

5 Comments

Aradesh3k · 11 months ago

Getting similar issues. I think the codex authorization server is down or something.

dedrisian-oai contributor · 11 months ago

Just to confirm, this is latest prod or alpha? Can you attach the exact version?

firmai · 10 months ago

latest prod

etraut-openai contributor · 8 months ago

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.

evalphobia · 8 months ago

I struggled this issue more than 1month.

[2025-12-10T13:17:18] User instructions:
hello
[2025-12-10T13:17:22] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 1/5 in 191ms…
[2025-12-10T13:17:26] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 2/5 in 382ms…
[2025-12-10T13:17:30] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 3/5 in 800ms…
[2025-12-10T13:17:35] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 4/5 in 1.568s…
[2025-12-10T13:17:41] stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 5/5 in 3.304s…
[2025-12-10T13:17:48] ERROR: exceeded retry limit, last status: 401 Unauthorized

I solved in my situation finally.

before v0.34

You can use OPENAI_API_KEY envvar (I used this version)

export OPENAI_API_KEY='sk-svcacct-...'
codex exec -m "gpt-5.1-codex-mini" --full-auto "hello"
after v0.36

You should use codex login --api-key command explicitly,

codex login --api-key "$OPENAI_API_KEY"
codex exec -m "gpt-5.1-codex-mini" --full-auto "hello"
after v0.46

Use codex login --with-api-key to follow the instruction below,
https://github.com/openai/codex/blob/main/docs/authentication.md#usage-based-billing-alternative-use-an-openai-api-key

echo $OPENAI_API_KEY | codex login --with-api-key
codex exec -m "gpt-5.1-codex-mini" --full-auto "hello"