BLACK FRIDAYUntil Dec 8 (Tue) 23:59 JSTUntil Dec 8

Docs401 Invalid API key

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

401authentication_error (error.type in the Anthropic format; in the OpenAI format error.code is an empty string)

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

  1. 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
  2. The key is not sent: there is no Authorization: Bearer <key> header. On /v1/messages in the Anthropic format you can also send it in the x-api-key header
  3. The key is stopped, expired or deleted
  4. 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

  1. Check the key on its own. If the last line of the following command shows 200 and 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"
  1. 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
  2. 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
  3. If this happens in Claude Code, check that ANTHROPIC_API_KEY does not still hold another key (such as an Anthropic key). Claude Code sends the key in this variable in the x-api-key header (Claude Code)