401 Invalid API key (wrong or unusable API key)
Causes and fixes when Echo Token Station's API returns HTTP 401 and "Invalid API key". It is returned when the key is wrong, missing, stopped, expired or deleted, or has used up its spending limit.
This error is returned when the API key is wrong or cannot be used.
Example
OpenAI format (/v1/chat/completions and so on):
JSON
{"error":{"code":"","message":"Invalid API key","type":"api_error"}}Anthropic format (/v1/messages):
JSON
{"type":"error","error":{"type":"authentication_error","message":"Invalid API key"}}Common causes
- The key string is wrong: you entered a key for another service (OpenAI, Anthropic and so on), or part of the key was lost when you copied it
- The key is not sent: there is no
Authorization: Bearer <key>header. On/v1/messagesin the Anthropic format you can also send it in thex-api-keyheader - The key is stopped, expired or deleted
- The key has used up its spending limit: a key that has used up its limit returns 401. When the remaining limit is only smaller than the estimated price of this request, you get 403 instead (403 insufficient_quota)
How to fix
- Check the key on its own. If the last line of the following command shows
200and above it is JSON with the list of models, the key works
bash
curl -sS -w '\n%{http_code}\n' "https://token.echohub.io/v1/models" \
-H "Authorization: Bearer $ECHO_API_KEY"- If it shows
401, check in API keys in the console that the key is not stopped or expired and that it has spending limit left. An expired key resumes as the same key when you extend its expiry with Change restrictions - If the key itself is wrong or you deleted it, issue a new key and replace it in the settings of your tools and programs
- If this happens in Claude Code, check that
ANTHROPIC_API_KEYdoes not still hold another key (such as an Anthropic key). Claude Code sends the key in this variable in thex-api-keyheader (Claude Code)
Related
- Errors and fixes: other errors and the error body format
- API keys and usage: issuing keys, stopping and resuming them, changing the spending limit
- 403 insufficient_quota: when the balance or the key's spending limit is not enough