TroubleshootingGuide
API 401 or 404 error: wrong key, base URL or model id
Read the status code, find which of three things is wrong (key, base URL, model id) and confirm the fix with one curl request.

On this page
Your request failed with a status code and you are not sure what to touch first. Short answer: 401 usually points to the key, 404 usually means you are knocking in the wrong place — either the address (base URL and path) or the model id. Three things to check, in this order, and one curl command that proves the fix.
OpenAI's error-codes page (checked 26 October 2026) lists two 401 messages: "Invalid Authentication" and "Incorrect API key provided". The fix it gives is the same for both: check the key or generate a new one. The page documents no 404 for the API itself, so for 404 the rule below comes from how OpenAI-compatible endpoints work, not from that page.
The quick way to tell them apart#
Scroll the table right →
| Status | What the server is saying | Look at first |
|---|---|---|
| 401 | usually: I don't accept this key | the key, and which provider it belongs to |
| 404 on every model | usually: there is nothing at this address | base URL and /v1 |
| 404 only on one model | usually: the address is fine, this model id isn't known | the model id |
The wording of the message depends on the server and on your tool (Cline, Aider, OpenCode and Continue each wrap errors their own way), so start from the number, then confirm with the curl check below.
401: the key doesn't match the endpoint#
The classic story: you moved a tool to a new provider, changed the base URL, and left the old provider's key in the config. The address is new, the key is the old one, and the server answers 401. Nothing is broken; the key just belongs to a different house.
What to check:
- Which provider issued the key? It must be the one whose address you are calling. A key for one service is not valid on another.
- Stray characters. A space or a line break pasted with the key, or quotes that ended up inside the value.
- Where the tool reads it from. An environment variable that is set in one terminal and not in the one your editor started from is a frequent cause. If the tool has both a config file and an environment variable, find out which wins.
- A revoked or deleted key. A key you deleted or revoked stops working — create a new one and put it in the config.
If you are not sure how keys work or where to keep them, what an API key is and how to store it safely covers it in plain words.
404 on every model: the address is wrong#
The base URL for CheapTokens is https:/. Tools and SDKs append the endpoint path themselves, so the usual slips are about /v1:
- Missing
/v1: the tool ends up callinghttps:/./ api. cheaptokens. dev/ chat/ completions - Doubled
/v1: you pasted the full path into a field that already adds it, and gethttps:/./ api. cheaptokens. dev/ v1/ v1/ chat/ completions - Wrong flavour: OpenAI-style tools and the OpenAI SDK take the address with
/v1. The Anthropic SDK and Claude Code take the address without/v1:https:/./ api. cheaptokens. dev
If you have ever wondered what exactly a base URL is and which part of it the tool adds, this explainer walks through it. For the Anthropic side, see the Anthropic Python SDK with CheapTokens.
404 on one model: the model id#
This one catches people who copy a name from a price table or from another provider. A price table might say DeepSeek-; the API wants the full gateway id, with the developer prefix and the release:
Scroll the table right →
| Where you saw it | What the API needs |
|---|---|
| DeepSeek-V4-Flash | deepseek- |
| GLM-5.3-Flash | zai- |
| MiniMax-M2.7 | MiniMaxAI/ |
Short ids from price labels are not accepted by the API, and spelling matters: capital letters, the slash, the -0731 suffix. Copy the id from the CheapTokens documentation rather than typing it from memory — different providers name the same model differently. To see the exact ids available to your key, call GET https:/ with the same Authorization header and copy the id from the list:
curl https://api.cheaptokens.dev/v1/models \
-H "Authorization: Bearer YOUR_API_KEY"If the name logic in the table looks odd, how to read AI model names explains alias versus pinned version.
Prove the fix with one curl command#
Take the tool out of the picture and call the API directly. Replace the key placeholder with your own:
curl https://api.cheaptokens.dev/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-ai/DeepSeek-V4-Flash-0731",
"messages": [{"role": "user", "content": "Say hi in one word."}],
"max_tokens": 20
}'This one request has all three suspects in it: the key in the header, the base URL in the first line, the model id in the body. A JSON reply with a choices array means all three are right, and whatever your tool does differently is the problem. If it fails, change one thing at a time:
- 401 → swap in the key you got from CheapTokens and run again.
- 404 → compare the URL character by character with the one above, then the model id.
After curl works, copy the same three values into the tool: the key, the base URL (https:/, or without /v1 for Anthropic SDK and Claude Code) and the full model id.
If it still doesn't work#
- Same error in the tool, curl is fine. The tool is reading an old key or URL from somewhere else: a second config file, a saved profile, an environment variable. Restart the tool after changing it.
- Not sure the model id is right. Call
GET /v1/modelswith your key and copy the id from the list. - Connection refused, timeouts, certificate errors. That is not a 401 or 404; see common connection errors.
- Not sure what the first request should look like. Your first API request goes step by step, and the docs have the full reference.
The habit worth keeping: when a call fails, read the number first. 401 usually means the key, 404 usually the address or model id, and curl settles it. That sorts out most of these errors before you open a single log.



