Skip to main content
Watch: I Built an AI App Without Leaving Databricks

Claude Code error

Claude Code: Invalid API key · Fix external API key

Error message
Invalid API key · Fix external API key

Status: WorkaroundLast verified 4 documented fixes2 sources

What it means

The ANTHROPIC_API_KEY environment variable or apiKeyHelper script returned a key the API rejected, or Claude Code blocked the key before sending it because it contains a character HTTP headers cannot carry (for example a line break).

Causes

  • A typo or revoked key
  • A stale key loaded from a .env file by direnv, dotenv shell plugins, or IDE terminals
  • A key pasted with an invisible character or stray line break
  • An apiKeyHelper script that does not print a valid key on stdout

How to fix it

  1. Fix 1.

    Check for typos and confirm the key has not been revoked in the Console.

  2. Fix 2.

    Inspect what is set in the same shell (PowerShell: Get-ChildItem Env:ANTHROPIC*).

    Snippet
    env | grep ANTHROPIC
  3. Fix 3.

    Unset ANTHROPIC_API_KEY and run /login to use subscription auth instead.

    Terminal
    unset ANTHROPIC_API_KEY
  4. Fix 4.

    If the key comes from apiKeyHelper, run the script directly to confirm it prints a valid key on stdout. Run /status to confirm the active credential source.

    Slash command
    /status

More Claude Code errors

All 18 Claude Code errors

FAQ

What does "Invalid API key · Fix external API key" mean in Claude Code?

The ANTHROPIC_API_KEY environment variable or apiKeyHelper script returned a key the API rejected, or Claude Code blocked the key before sending it because it contains a character HTTP headers cannot carry (for example a line break).

How do I fix "Invalid API key · Fix external API key"?

There are 4 documented fixes. Start with the first: Check for typos and confirm the key has not been revoked in the Console.

Is this Claude Code error fixed?

Status: Workaround. No release removes the cause. The documented fixes work around it.

Sources

Last verified against 2 sources: official docs, maintainer replies and release notes.

Newsletter

Fixes for the tools you use, weekly

One email per week. New coding agent releases, what broke, and how developers are working around it.