Home → Help
401 {"code":"INVALID_API_KEY","message":"Invalid API key"}AuthenticationError: Error code: 401Incorrect API key providedThis is worth separating from the HTML-instead-of-JSON case. Getting a clean JSON 401 proves your base URL is correct and the request is being routed properly. You are one small fix away rather than debugging the wrong layer.
The most common cause is not a wrong key at all — it is an invisible character. Copying from a terminal or a web UI often picks up a trailing newline or a non-breaking space, and the comparison fails on a key that looks identical on screen.
Print the key's length and check it against what the dashboard shows. An off-by-one is the giveaway:
# Python
import os
k = os.environ["API_KEY"]
print(len(k), repr(k[-4:]))
# shell
printf '%s' "$API_KEY" | wc -c
If repr() shows '\n' or the length is one more than expected, that is your answer.
curl https://apiclan.us/v1/models -H "Authorization: Bearer YOUR_KEY". Keys are scoped to one group, so a key made for one plan will not work on another.Last checked 2026-08-24. Written from problems diagnosed on a live OpenAI-compatible gateway, not collected from other sites.