[BUG]
"Authentication fails with 'Invalid API key' error despite valid key"
Description:
Environment:
- OS: macOS (Darwin 24.6.0)
- Claude Code version: 1.0.93
- Node.js version: [
⎿ v22.17.0
⏺ v22.17.0
Issue:
Authentication consistently fails with "Invalid API key · Fix external API key" error despite using valid API keys.
Steps to reproduce:
- Run
claude auth - Enter valid API key
- Gets "Invalid API key" error
- Even with the error I am somehow logged in but get the api invalid when trying to use certain features i.e. chat and I have wasted my limits probably 10 times trying to troubleshoot
Troubleshooting attempted:
- Tried multiple fresh API keys from console.anthropic.com
- Cleared config:
rm -rf ~/.config/claude-code - Reinstalled:
npm install -g @anthropic-ai/claude-code@latest - Set ANTHROPIC_API_KEY environment variable
- All authentication attempts fail with same error
Expected behavior:
Authentication should succeed with valid API key
Current behavior:
All authentication attempts fail regardless of API key validity
***I have done all of this in fresh terminal even complete fresh install of vs code and extension. This is just the latest it's been 3 days and all i get is redirected to other posts that dont work. I am logged in but anything I do says api key invalid this is beyond frustrating***
⎿ Error: Cannot set 'api_key'. Only these keys can be modified: apiKeyHelper, installMethod, autoUpdates, theme, verbose, preferredNotifChannel, shiftEnterKeyBindingInstalled, editorMode,
hasUsedBackslashReturn, supervisorMode, autoCompactEnabled, diffTool, env, tipsHistory, todoFeatureEnabled, messageIdleNotifThresholdMs, autoConnectIde, autoInstallIdeExtension,
autocheckpointingEnabled, checkpointingShadowRepos
⏺ The claude config command doesn't allow setting the API key directly. Try the authentication flow:
⏺ Bash(claude auth)
⎿ Error: Invalid API key · Fix external API key
⏺ The authentication is still failing. This appears to be a persistent bug. You may need to:
- Check if there's a newer version: npm install -g @anthropic-ai/claude-code@latest
- Report this issue at https://github.com/anthropics/claude-code/issues
The API key validation seems to be broken in your Claude Code installation.
npm install -g @anthropic-ai/claude-code@latest
⏺ Bash(npm install -g @anthropic-ai/claude-code@latest)
⎿ changed 3 packages in 2s
2 packages are looking for funding
run npm fund for details
⏺ Now try authenticating again:
⏺ Bash(claude auth)
⎿ Error: Invalid API key · Fix external API key
⏺ Still failing. Let's check the version to see if it updated:
⏺ Bash(claude --version)
⎿ 1.0.93 (Claude Code)
⏺ Same version - no update was available. This is definitely a bug that needs to be reported. The authentication system is completely broken for your installation.
<img width="3793" height="961" alt="Image" src="https://github.com/user-attachments/assets/1727dadc-c995-49e1-87ff-233c30e48906" />
<img width="3766" height="1009" alt="Image" src="https://github.com/user-attachments/assets/8730c6c3-87df-4006-8483-1496f951966f" />
<img width="2816" height="867" alt="Image" src="https://github.com/user-attachments/assets/6ce96d2f-142b-47dc-8a19-9abd35eadf5a" />
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗