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 · 日本語版

401 authentication_error Fix a setting, login or environment Official documentation checked on

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 credentials
  • Invalid API key · Fix external API key
  • Please 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_KEY that was revoked or belongs to a disabled organization.
  • A stale key loaded from a .env file 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

  1. Run /status. If an API key row is active, the key is what is being sent; if only your login appears, the login is.
  2. 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, run unset ANTHROPIC_API_KEY (PowerShell: Remove-Item Env:ANTHROPIC_API_KEY) and then /login.
  3. For a login: run /login once. A fresh login replaces a revoked credential.
  4. If the same message returns for the same login account, the account or organization is no longer active. Check the account and organization that /status reports and ask your organization admin to restore access.
  5. If ANTHROPIC_BASE_URL points at a gateway, the text after 401 is the gateway's message. Fix the credential the gateway expects, since /login does 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

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.

Back to the error list (10 errors)