Invalid API Key Format sk-ant — Fix (2026)

The Error

Error: Invalid API key format. Expected key starting with 'sk-ant-api03-' but received 'sk-ant-api01-...'

This error appears when you pass an outdated API key to Claude Code or the Anthropic SDK. Anthropic deprecated the sk-ant-api01 and sk-ant-api02 prefixes in early 2026.

The Fix

  1. Go to the Anthropic Console and generate a new key:
open https://console.anthropic.com/settings/keys
  1. Replace your old key in your environment:
export ANTHROPIC_API_KEY="sk-ant-api03-your-new-key-here"
  1. Update your shell profile so it persists:
echo 'export ANTHROPIC_API_KEY="sk-ant-api03-your-new-key-here"' >> ~/.zshrc
source ~/.zshrc
  1. Verify the key works:
claude --version && claude "say hello"

Why This Happens

Anthropic rotates API key prefixes when they change their authentication infrastructure. The sk-ant-api01 prefix was used during the 2024 beta, and sk-ant-api02 during 2025. Keys with old prefixes are rejected at the gateway level before they even reach the model.

If That Doesn’t Work

  • Check if your key is stored in a .env file that overrides the shell export:
grep -r "sk-ant" .env ~/.claude/ 2>/dev/null
  • If using the SDK programmatically, ensure you are not hardcoding the key:
python -c "import anthropic; print(anthropic.Anthropic().messages.create(model='claude-sonnet-4-20250514', max_tokens=10, messages=[{'role':'user','content':'hi'}]))"
  • Confirm your organization has not been migrated to OAuth-based auth, which uses a different flow entirely.

Prevention

Add this to your CLAUDE.md:

# API Key Management
- Never hardcode API keys. Always use ANTHROPIC_API_KEY environment variable.
- Verify key prefix matches sk-ant-api03 before deployment.
- Store keys in a secrets manager, not in .env files committed to git.

See Also

Frequently Asked Questions

Does this error affect all operating systems?

This error can occur on macOS, Linux, and Windows (WSL). The exact error message may differ slightly between platforms, but the root cause and fix are the same. macOS users may see additional Gatekeeper or notarization prompts. Linux users should check that the relevant system packages are installed. Windows users should ensure they are running inside WSL2, not native Windows.

Will this error come back after updating Claude Code?

Updates can occasionally reintroduce this error if the update changes default configurations or dependency requirements. After updating Claude Code, verify your project still builds and runs correctly. If the error returns, reapply the fix and check the changelog for breaking changes.

Can this error cause data loss?

No, this error occurs before or during an operation and does not corrupt existing files. Claude Code’s edit operations are atomic — they either complete fully or not at all. However, if the error occurs during a multi-step operation, you may have partial changes that need to be reviewed with git diff before continuing.

How do I report this error to Anthropic if the fix does not work?

Open an issue at github.com/anthropics/claude-code with: (1) the full error message including stack trace, (2) your Node.js version (node --version), (3) your Claude Code version (claude --version), (4) your operating system and version, and (5) the command or operation that triggered the error.

This fix also applies if you see variations of this error:

  • Connection or process errors with similar root causes in the same subsystem
  • Timeout variants where the operation starts but does not complete
  • Permission variants where access is denied to the same resource
  • Configuration variants where the same setting is missing or malformed

If your specific error message differs slightly from the one shown above, the fix is likely the same. The key indicator is the operation that failed (shown in the stack trace) rather than the exact wording of the message.

Try it: Paste your error into our Error Diagnostic for an instant fix.