Troubleshooting · Codex CLI

Codex auth.json / Login Errors — API Key Auth Instead

Codex login state lives in ~/.codex/auth.json, and a stale or missing file produces login prompts and auth failures. When to re-login and when a custom provider skips it entirely.

What you see

codex auth.json error

Why it happens

  • auth.json is missing, unreadable or stale, so the default provider has no working login.
  • The login belongs to a different account or plan state than the session expects — refreshing tokens no longer succeed.
  • The failure is misattributed: with a custom provider and env_key, ChatGPT-login state is irrelevant, and the real problem is the environment variable or profile.

How to fix it

  • For the default provider, re-run the login flow so auth.json is rewritten fresh.
  • For a custom provider, auth.json does not participate: authentication is the env_key variable. Check the profile is actually selected and the variable is set in the running shell.
  • Keep the two paths mentally separate — subscription login for the default provider, API key for custom providers. Errors from one are not fixed in the other.

Related searches

  • codex not logged in
  • codex login failed

FAQ

Does a custom provider in Codex use auth.json?+
No. A [model_providers.*] entry authenticates with the environment variable named by env_key. auth.json only carries the default ChatGPT login.
Why does Codex keep asking me to log in?+
Its stored login state cannot be refreshed. Re-login to rewrite it — or, if you meant to use a custom provider, select the profile explicitly so no login is needed.
Can I run Codex without any ChatGPT subscription?+
Yes — with a custom provider profile and that provider's API key in the environment, Codex runs entirely on API-key auth.

Skip the broken setup

apiToken.sale serves the standard Anthropic API — same models, same SDKs, one prepaid balance. Point your tool's base URL at it, and the config on this page works as written.