Codex: 401 Unauthorized, Incorrect API key provided
Codex read a key (from `CODEX_API_KEY` or `codex login --with-api-key`) and OpenAI rejected it: mistyped, revoked, or from a project without access. The exact message, why Codex prints it, and the fix.
Updated November 23, 2026 · Checked against Codex 0.157.1, reproduced in EnvHaven 1.9.0
The message
ERROR: unexpected status 401 Unauthorized: Incorrect API key provided: sk-proj-*****. You can find your API key at https://platform.openai.com/account/api-keys.
What it means
Codex read a key (from CODEX_API_KEY or codex login --with-api-key) and OpenAI rejected it: mistyped, revoked, or from a project without access.
Fix
- Create a new key at platform.openai.com and run
codex login --with-api-keyagain. - Or switch to a ChatGPT sign-in with
codex login, which bills your ChatGPT plan instead of API credits.
In an EnvHaven workspace
Yes, if a wrong key is set.
Where this comes from
This message was produced by Codex (Codex 0.157.1) itself, in a throwaway EnvHaven 1.9.0 container, on 2026-11-23; the text above is copied from that output.