Home / Blog / Pricing

Pricing

Claude Code "API Error: 401": Invalid Authentication Credentials Fixes

Claude Code says "API Error: 401" with "Invalid authentication credentials"? What the 401 means, how it differs from invalid-key, and the documented fixes.

8 min read

Error strings quoted from Claude Code GitHub issues #69706 and #5893 (verified Nov 7, 2026). Causes and fixes checked Nov 7, 2026 in Claude Code’s error reference, authentication docs and Anthropic’s API error docs. Every source is listed at the bottom. No affiliate links on this page (how we work).

The exact errors: API Error: 401 Invalid authentication credentials

The classic title string, from #69706 (verified Nov 7, 2026):

Please run /login · API Error: 401 Invalid authentication credentials

The mid-run JSON cousin, from #5893 (verified Nov 7, 2026):

API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth authentication is currently not supported."}}

The one-line answer: a 401 means the credentials Claude Code sent were rejected. It is not a usage limit. Anthropic’s API docs define 401 - authentication_error as an issue with the API key (malformed, revoked, or expired) (API errors, verified Nov 7, 2026). Claude Code’s own error reference adds the account-side story: the API accepted the credential format but rejected the account or organization behind it — for example a key that was revoked, an organization that was disabled, or an account that was deactivated, so an expired token is not the only cause (errors, verified Nov 7, 2026).

If the banner is Invalid API key · Please run /login, that sister string lives in Claude Code invalid API key. If it is Login expired · Please run /login or non-interactive Failed to authenticate: OAuth session expired and could not be refreshed, that is Claude Code OAuth session expired. This post owns the API Error: 401 / Invalid authentication credentials family only.

It is Catch Me If You Can energy: Claude Code is presenting a passport, and the border agent is saying the document format looks right but the person behind it does not clear. Frank Abagnale would be impressed. You will not be.

Which 401 do you have?

Read the part after 401. That is where the cause lives.

MessageLikely causeFix
Invalid auth credentialsAccount/org refused/status, then /login
authentication_error JSONOAuth path rejectedClean re-login
Login expired (sister)Saved OAuth lapsedOAuth expired
Invalid API key (sister)Bad/stray key stringInvalid API key

Causes from the issues and docs listed under each section below, verified Nov 7, 2026. Sister rows point at their own posts.

Invalid authentication credentials

#69706 (opened Jun 20, 2026, still open as of Nov 7, 2026) is on Claude Code v2.1.183 with a Pro subscription. The repeated UI line is Please run /login · API Error: 401 Invalid authentication credentials. The reporter tried claude logout/login, deleted %APPDATA%\Claude, and reinstalled — still failed. User comments (not maintainer guidance) mention an empty refreshToken in ~/.claude/.credentials.json; copying a valid refreshToken from another machine cleared it for one person. Treat that as a workaround report, not an Anthropic-published fix. Other commenters say Pro with low usage still 401’d on Linux, Mac and Codespaces. No Anthropic maintainer fix is stated in the thread.

Anthropic’s error reference recovery path for this display string: run /status first; if an approved ANTHROPIC_API_KEY is active it takes precedence so /login does not replace it — rotate the key or unset ANTHROPIC_API_KEY (PowerShell: Remove-Item Env:ANTHROPIC_API_KEY); if only login is configured, run /login; if the same login keeps failing, the account or org may be inactive; if ANTHROPIC_BASE_URL points at a gateway, the text after 401 is the gateway’s message (errors, verified Nov 7, 2026).

Mid-run authentication_error JSON (“OAuth authentication is currently not supported.”)

#5893 (opened Aug 16, 2025, still open, 64 comments as of the Nov 7, 2026 fetch) is the mid-session JSON blast. /logout plus login did not clear it for the reporter. User comments claim rm -rf ~/.claude plus deleting ~/.claude.json then re-login, or /login then /exit then restart claude on Ubuntu/macOS. Those are user reports, not a maintainer resolution — the first page of comments has no official fix.

Important honesty check: an official doc entry for the exact JSON message OAuth authentication is currently not supported. is not published among the sources fetched Nov 7, 2026 (it appears in #5893). Quote it as a GitHub-reported string, not as something Anthropic’s error reference defines by name.

This is the Usual Suspects twist: the credential Claude Code thought it was holding turns out to be Keyser Söze — an identity that is not who you assumed when the session started.

Nearby, but not this post: Login expired

Claude Code’s error reference has a separate nearby section for Login expired · Please run /login, and for non-interactive Failed to authenticate: OAuth session expired and could not be refreshed with code authentication_failed (errors, verified Nov 7, 2026). Those are distinct from the 401 Invalid authentication credentials string family. Full walkthrough: Claude Code OAuth session expired.

How to fix Claude Code API Error 401, in order

Each step says where it comes from.

  1. Run /status first. See which auth is active before you change anything (errors, verified Nov 7, 2026). Authentication docs cover the same /status / /login flow and env-key approve/decline memory (authentication, verified Nov 7, 2026).
  2. Unset overriding env vars if you meant subscription login. ANTHROPIC_API_KEY (and check ANTHROPIC_AUTH_TOKEN / ANTHROPIC_BASE_URL). In -p mode the key is always used when present. Help 11145838 notes that a set ANTHROPIC_API_KEY switches you to API usage charges (support 11145838, verified Nov 1, 2026).
  3. Do a clean /logout then /login. Cheap, and it fixes real token problems. It failed for some #69706 / #5893 reporters, which is why step 1 matters first.
  4. Refresh the VS Code / IDE extension login if the 401 is only in the editor. Same credential precedence applies; a stale IDE session can disagree with a healthy terminal login.
  5. If a gateway sits on ANTHROPIC_BASE_URL, read the text after 401. That trailing message is the gateway’s, per the error reference — signing into Anthropic again may not change it.
  6. Check status.claude.com. As of Nov 7, 2026 the page showed the aggregate banner All Systems Operational (verified Nov 7, 2026). No separate live Claude Code 401 incident was claimed beyond that banner.
  7. Still stuck? File /feedback with the full error line, Claude Code version, and whether /status showed a key or a login. Watch #69706 / #5893 if your string matches.

What not to do: don’t burn a second account to “reset” auth, don’t paste someone else’s refreshToken from a random forum as policy, and don’t run a credential-relay tool. A 401 is Anthropic (or your gateway) rejecting who you are for this request.

401 vs invalid-api-key vs 400 vs usage-limit

Code / stringMeaningRead
API Error: 401Credentials rejectedYou’re here
Invalid API keyKey string bad/blockedInvalid API key
Login expiredOAuth needs refreshOAuth session expired
API Error: 400Request malformedAPI Error 400
Usage limitPlan window spentUsage limit reached

Meanings from Anthropic API errors and the Claude Code error reference, verified Nov 7, 2026, plus the linked sister posts.

Short version: 401 here is “credential/account refused.” Invalid-api-key is the dedicated bad-key UX. Login expired is the OAuth-lapsed sister. A 400 is a broken request (Claude Code API Error 400). A session or weekly cap is Claude Code usage limit reached.

Whether a failed 401 counts against usage is not published as of Nov 7, 2026, so I will not guess. Plan names for older threads: Max is $100; Ultra is $200 (formerly Max 20x) (support 17728952, verified Nov 1, 2026).

Here’s what I’d do

Run /status. If a stray ANTHROPIC_API_KEY is active and you wanted Pro, Max or Ultra, unset it, relaunch, then one clean /logout and /login. If only login is configured and the same 401 returns, treat account/org status as the next check and keep #69706 open. If the JSON says OAuth authentication is currently not supported., quote #5893 and avoid inventing a doc section Anthropic has not published for that exact line.

If 401 loops keep eating the morning, keep a backup ready. Our Claude Code alternatives list and AI coding tools compared page cover the options with dated prices.

FAQ

What does Claude Code API Error: 401 Invalid authentication credentials mean? The credentials Claude Code sent were rejected — Anthropic’s error reference says the format may be recognized while the account or organization behind it is refused (verified Nov 7, 2026).

Does API Error 401 mean my Claude plan expired? Not by itself. Plan usage limits use their own messages; a 401 is an authentication refusal. Whether your subscription is inactive is a separate account check after /status and /login.

How is API Error 401 different from Invalid API key? Invalid API key is the dedicated bad/blocked-key UX covered in Claude Code invalid API key; API Error 401 Invalid authentication credentials is the broader “credentials rejected” family, including account/org refusal wording in the error reference.

Will /login fix API Error: 401 Invalid authentication credentials? Sometimes. The docs say to /login when only login is configured, but if an approved ANTHROPIC_API_KEY is active it takes precedence so /login will not replace it until you unset or rotate the key.

What about the JSON OAuth authentication is currently not supported. line? That exact string is reported in #5893; an official doc entry for it was not published among sources fetched Nov 7, 2026.

Sources

  1. Claude Code GitHub issue #69706 (API Error: 401 Invalid authentication credentials; open): https://github.com/anthropics/claude-code/issues/69706 (verified 2026-11-07)
  2. Claude Code GitHub issue #5893 (mid-run authentication_error JSON; open): https://github.com/anthropics/claude-code/issues/5893 (verified 2026-11-07)
  3. Claude Code error reference (§ API Error: 401 Invalid authentication credentials; Login expired sister section): https://code.claude.com/docs/en/errors (verified 2026-11-07)
  4. Claude Code authentication (/login, /status, env-key precedence): https://code.claude.com/docs/en/authentication (verified 2026-11-07)
  5. Anthropic API errors (401 - authentication_error): https://docs.claude.com/en/api/errors (verified 2026-11-07)
  6. Anthropic help, Use Claude Code with your Pro, Max or Ultra plan (ANTHROPIC_API_KEY → API charges; /status): https://support.claude.com/en/articles/11145838-use-claude-code-with-your-pro-max-or-ultra-plan (verified 2026-11-01)
  7. Anthropic help, What is the Ultra plan (Max 20x renamed Ultra): https://support.claude.com/en/articles/17728952-what-is-the-ultra-plan (verified 2026-11-01)
  8. Claude status page: https://status.claude.com (reachable 2026-11-07; aggregate “All Systems Operational”)

Related reading