Codex cli (recent)Auth / Login
Codex CLI: 401 Unauthorized
Error: 401 Unauthorized
- Affected versions
- cli (recent)
- Fixed in
- —
- Last verified
- Codex CLI (recent)
Root cause
Auth state is stale or the wrong credential type is in use (e.g. an expired login session, or an API key that doesn't match the account/plan the CLI expects).
How to reproduce
Run a Codex command after the session expired; requests return 401.
Solutions (2)
Ordered by community votes. Always check the verified version before applying.
34
#1Applies to cli (recent)
Re-authenticate: log out and log back in (`codex logout` then `codex login`) so a fresh token is issued.
Last verified: Codex CLI (recent) · community
19
#2Applies to cli (recent)
If using an API key, confirm it's valid and matches the intended account/org; remove conflicting OPENAI_API_KEY env vars that override the login.
Last verified: Codex CLI (recent) · community