Invalid API key · Fix external API key
Bug Description
Claude is stuck in API billing mode even though there is no API env variable set and I have linked claude code to my pro max account successfully
Environment Info
- Platform: darwin
- Terminal: iTerm.app
- Version: 2.0.20
- Feedback ID:
Errors
[{"error":"Error: 401 {\"type\":\"error\",\"error\":{\"type\":\"authentication_error\",\"message\":\"invalid x-api-key\"},\"request_id\":\"req_011CUBgWE2fdbDGiPKTUQTwy\"}\n at generate (/$bunfs/root/claude:199:83061)\n at makeRequest (/$bunfs/root/claude:353:5345)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-10-16T22:40:20.395Z"},{"error":"Error: 401 {\"type\":\"error\",\"error\":{\"type\":\"authentication_error\",\"message\":\"invalid x-api-key\"},\"request_id\":\"req_011CUBgWEjLRjNADu5mxAaDG\"}\n at generate (/$bunfs/root/claude:199:83061)\n at makeRequest (/$bunfs/root/claude:353:5345)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-10-16T22:40:20.532Z"},{"error":"Error: 401 {\"type\":\"error\",\"error\":{\"type\":\"authentication_error\",\"message\":\"invalid x-api-key\"},\"request_id\":\"req_011CUBgWFLJ9vhxu4yndaVXV\"}\n at generate (/$bunfs/root/claude:199:83061)\n at makeRequest (/$bunfs/root/claude:353:5345)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-10-16T22:40:20.685Z"},{"error":"Error: 401 {\"type\":\"error\",\"error\":{\"type\":\"authentication_error\",\"message\":\"invalid x-api-key\"},\"request_id\":\"req_011CUBgWFyzR6jLnJPMbr6SH\"}\n at generate (/$bunfs/root/claude:199:83061)\n at makeRequest (/$bunfs/root/claude:353:5345)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-10-16T22:40:20.828Z"},{"error":"Error: 401 {\"type\":\"error\",\"error\":{\"type\":\"authentication_error\",\"message\":\"invalid x-api-key\"},\"request_id\":\"req_011CUBgWHtau4nGTQasDjTn4\"}\n at generate (/$bunfs/root/claude:199:83061)\n at makeRequest (/$bunfs/root/claude:353:5345)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-10-16T22:40:21.270Z"},{"error":"Error\n at BM (/$bunfs/root/claude:27:1142)\n at <anonymous> (/$bunfs/root/claude:32:9841)\n at emit (node:events:92:22)\n at endReadableNT (internal:streams/readable:862:50)\n at processTicksAndRejections (native:7:39)\n at request (/$bunfs/root/claude:34:2146)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-10-16T22:40:21.345Z"},{"error":"Error\n at BM (/$bunfs/root/claude:27:1142)\n at <anonymous> (/$bunfs/root/claude:32:9841)\n at emit (node:events:92:22)\n at endReadableNT (internal:streams/readable:862:50)\n at processTicksAndRejections (native:7:39)\n at request (/$bunfs/root/claude:34:2146)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-10-16T22:41:00.437Z"},{"error":"Error: 401 {\"type\":\"error\",\"error\":{\"type\":\"authentication_error\",\"message\":\"invalid x-api-key\"},\"request_id\":\"req_011CUBgZBNWMSJZRbJ46YKUy\"}\n at generate (/$bunfs/root/claude:199:83061)\n at makeRequest (/$bunfs/root/claude:353:5345)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-10-16T22:41:00.449Z"}]
Claude location: /Users/shaperosteve/.local/bin/claude
Diagnostics
└ Currently running: native (2.0.21)
└ Path: /Users/shaperosteve/.local/bin/claude
└ Invoked: /Users/shaperosteve/.local/share/claude/versions/2.0.21
└ Config install method: native
└ Auto-updates enabled: false
└ Search: OK (bundled)
▐▛███▜▌ Claude Code v2.0.21
▝▜█████▛▘ Sonnet 4.5 · API Usage Billing
▘▘ ▝▝ /Users/shaperosteve/social-media-app`
I have gone through 3-4 posts with similar problems and tried everything. Re-installing Claude locally, re-installing with latest version 2.0.21. I tried all the OAuth stuff found here https://github.com/anthropics/claude-code/issues/9403. Absolutely nothing is working. OAuth etc is not my area of expertise.
Here's some stuff I gathered from reading other posts:
```security unlock-keychain ~/Library/Keychains/login.keychain-db security find-generic-password -s "Claude Code-credentials" -w {"claudeAiOauth":{"accessToken":"sk-ant...
security find-generic-password -s "Claude Code" -w security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
which claude: /Users/shaperosteve/.local/bin/claude
So everytime I run claude, I do /login, the login authenticates successfully, and then I get the "Invalid API key · Fix external API key" message.
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗