Claude Code 401 Error: Invalid Authentication Credentials or Invalid API Key
What Please run /login · API Error: 401 Invalid authentication credentials means, whether to wait, and what to check first.
Language: English · 日本語版
Wait or fix?
Fix it, starting with /status. A 401 means the API rejected the credential Claude Code sent, so waiting does not help. The first question is which credential was sent: your saved login or an API key from the environment. The fix differs for each, and running /login does not replace an approved ANTHROPIC_API_KEY, which takes precedence over your login.
Messages you may see
Please run /login · API Error: 401 Invalid authentication credentialsInvalid API key · Fix external API keyPlease run /login · API Error: 401 OAuth token has expired ...401 authentication_error
The exact wording changes a little between Claude Code versions and providers.
What the message means
Three similar messages belong here. "401 Invalid authentication credentials" means the API recognized the format of your credential but rejected the account or organization behind it, for example when a credential was recently revoked, an organization was disabled or removed your access, or the account was deactivated; an expired token is not the cause. "Invalid API key" means the key from ANTHROPIC_API_KEY or an apiKeyHelper script was rejected, or Claude Code blocked it before sending because it contained a character HTTP headers cannot carry, such as a line break. "OAuth token has expired" means the saved login is no longer valid because the automatic refresh failed. According to the authentication page, an approved API key in the environment is used ahead of your subscription login.
Common causes
- An approved
ANTHROPIC_API_KEYthat was revoked or belongs to a disabled organization. - A stale key loaded from a
.envfile by tools such as direnv, dotenv shell plugins or IDE terminals. - A typo or a line break in the key.
- A saved login that was revoked or has expired.
- With an LLM gateway in
ANTHROPIC_BASE_URL, a credential the gateway does not accept.
Check in this order
- Run
/status. If an API key row is active, the key is what is being sent; if only your login appears, the login is. - For a key: run
env | grep ANTHROPIC(PowerShell:Get-ChildItem Env:ANTHROPIC*) in the same shell, and check the key for typos or revocation in the Claude Console. To use your subscription instead, rununset ANTHROPIC_API_KEY(PowerShell:Remove-Item Env:ANTHROPIC_API_KEY) and then/login. - For a login: run
/loginonce. A fresh login replaces a revoked credential. - If the same message returns for the same login account, the account or organization is no longer active. Check the account and organization that
/statusreports and ask your organization admin to restore access. - If
ANTHROPIC_BASE_URLpoints at a gateway, the text after 401 is the gateway's message. Fix the credential the gateway expects, since/logindoes not change it.
We took the fixes from the official pages below and put them in order, with the quickest and most likely ones first.
How it differs from similar errors
- 403 Request not allowed appears after a successful login and is about the subscription, the account role or a proxy.
- "Not logged in · Please run /login" means no credential was available at all.
- "Credit balance is too low" can also come from an API key being used instead of your subscription.
Related errors
Official sources
- Claude Code error reference: 401 Invalid authentication credentials (checked 2026-11-20)
- Claude Code error reference: Invalid API key (checked 2026-11-20)
- Claude Code error reference: OAuth token revoked or expired (checked 2026-11-20)
- Claude Code authentication: Authentication precedence (checked 2026-11-20)
- Claude API errors: HTTP errors (401 authentication_error) (checked 2026-11-20)
Unofficial page. Not affiliated with, endorsed by, or sponsored by Anthropic, PBC. Claude and Claude Code are trademarks of Anthropic, PBC. Messages and fixes change with updates, so read the official pages as well.