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
- Go to the Anthropic Console and generate a new key:
open https://console.anthropic.com/settings/keys
- Replace your old key in your environment:
export ANTHROPIC_API_KEY="sk-ant-api03-your-new-key-here"
- Update your shell profile so it persists:
echo 'export ANTHROPIC_API_KEY="sk-ant-api03-your-new-key-here"' >> ~/.zshrc
source ~/.zshrc
- 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
.envfile 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
- Claude API Invalid API Key Format Error — Fix (2026)
- Claude API Key Organization Mismatch — Fix (2026)
- ANTHROPIC_API_KEY Not Set in Subprocess Fix
- API Key Region Mismatch eu-west-1 — Fix (2026)
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.
Related Error Messages
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.
Related Guides
Try it: Paste your error into our Error Diagnostic for an instant fix.