Claude Code · Sign-in
API Error: 401 Invalid authentication credentials
Fix “API Error: 401 Invalid authentication credentials” in Claude Code: find the active credential, rotate the key or log in again.
Message
The exact error
Please run /login · API Error: 401 Invalid authentication credentialsMeaning
What does API Error 401 mean in Claude Code?
This isn’t an expired token. Anthropic returns it when a credential was recently revoked, when your organisation was disabled or removed you, or when the account was deactivated. The credential may be your saved login or an ANTHROPIC_API_KEY, and the fix depends on which, so start by running /status. (An expired login reads OAuth token has expired instead.)
Causes
Is it my API key or my login?
- A revoked API key or login
- Your organisation disabled or removed your access
- A deactivated account
- A gateway set in
ANTHROPIC_BASE_URLrejecting its own credential
Fix
How do I fix API Error 401?
See which credential is active
Run
/status. If it shows anAPI keyrow that isn’t marked as not in use, an approvedANTHROPIC_API_KEYis the active credential and takes priority over your login, so/loginwon’t replace it.If it’s an API key
Rotate the key in the Console, or fall back to your subscription by removing it. To stop it coming back, also delete it from your shell profile (
~/.zshrc,~/.bashrc,~/.profile) or Windows user variables. The API key checker tests a new key from your browser before you use it.macOS / Linux unset ANTHROPIC_API_KEYWindows PowerShell Remove-Item Env:ANTHROPIC_API_KEYIf it’s your login
Run
/loginonce. If the credential was revoked, a fresh login replaces it. If the same error returns for the same account, ask your organisation’s admin to restore access.If an apiKeyHelper script supplies the key
After a 401, Claude Code re-runs the script and retries with its fresh output. If the script itself fails you see
Your apiKeyHelper script is failinginstead: run it by hand and make sure it prints only the key./logindoesn’t help while the setting is present.If you use a gateway
With
ANTHROPIC_BASE_URLset, the text after 401 is your gateway’s, and/loginwon’t change it; fix the credential the gateway expects.
Explained
Why do I get 401 right after logging in?
Most often an approved ANTHROPIC_API_KEY is still the active credential, so the new login is never used. /status shows an API key row in that case: unset the key, remove it from your shell profile and relaunch claude. If /status shows only your login and the 401 persists, the account or organisation it names is no longer active, which only an admin or Anthropic support can change. A key that is malformed rather than revoked shows Invalid API key, and no credential at all shows Not logged in.
Explained
What about “API Error: 403 Request not allowed”?
A 403 after logging in means the credential is valid but not allowed. On Pro or Max, check that your subscription is active at claude.ai/settings. On a Console account, you need the Claude Code or Developer role, which an admin assigns on the Console’s Members page. Behind a corporate proxy, the proxy may be blocking the request: see Anthropic’s network configuration guide, and Unable to connect to API for connection checks.
Explained
Why do I get 401 through a gateway or router?
With ANTHROPIC_BASE_URL pointing at an LLM gateway, proxy or router, the 401 text comes from that service, not from Anthropic. Check which credential it expects: a bearer token goes in ANTHROPIC_AUTH_TOKEN (sent as Authorization: Bearer), and an Anthropic-style key in ANTHROPIC_API_KEY (sent as X-Api-Key). /login can’t fix a gateway 401.
FAQ
Questions people ask
Why does Claude Code give a 401 right after I log in?
Most often an approved ANTHROPIC_API_KEY is still taking priority over your new login, so /login changes nothing; /status shows an API key row in that case. Unset the key, remove it from your shell profile and relaunch claude. If /status shows only your login and the 401 persists, your account or organisation may no longer be active: ask your admin.
What is the difference between 401 and 403 in Claude Code?
A 401 means the credential itself was rejected: revoked, or tied to an account or organisation that is no longer active. A 403 such as “Request not allowed” means the credential is valid but not permitted: an inactive subscription, a Console account without the Claude Code or Developer role, or a proxy blocking the request.
Why do I get 401 with claude-code-router or another proxy?
With ANTHROPIC_BASE_URL set, the 401 text comes from your gateway, not Anthropic, and /login can’t fix it. Check the key or token the gateway expects and how it is passed: ANTHROPIC_AUTH_TOKEN is sent as a bearer token, ANTHROPIC_API_KEY as an X-Api-Key header.
Related
Related errors
Keep exploring