Incorrect API key provided: what it means and how to fix it
Incorrect API key provided is a 401 error returned by the OpenAI API: per OpenAI's error-codes guide (checked 2026-12-04), the key in the request is not correct, for example because of a typo or an extra space, a key from another organization or project, or a key that was deleted or deactivated; CC Switch's API Key is invalid or lacks permission toast (Chinese UI: API Key 无效或无权限) appears, per its v4.0.47 source (checked 2026-12-04), when its model-list request gets HTTP 401 or 403. The fix is to send a current key issued by the server your client actually calls: check the base URL first, then the key and how it is written in the Authorization header. Router One's own key check answers a missing or invalid key with HTTP 401 and the code AUTH_INVALID_API_KEY, and its API reference shows the message invalid api key; the request is refused before any model is called, so it has no row in Dashboard → Logs. Below: where each wording comes from, the usual causes, a one-line key check, and how a 401 differs from the 402 and 403 a valid Router One key can still get.
Where each wording comes from
The text depends on which server answered and on how your client shows errors:
| Wording | Where it comes from | What it tells you |
|---|---|---|
| Incorrect API key provided | The OpenAI API's 401 for a key it does not accept, per OpenAI's error-codes guide and its help article on this error (both checked 2026-12-04). The help article shows the message quoting the key it received, mostly masked, and notes that it can show an old key you no longer use. | The server that answered did not accept the key. Compare the visible end of the masked key with the key you meant to send. |
invalid api key, code AUTH_INVALID_API_KEY, type authentication_error | Router One's key check, per its API reference. | Router One did not accept the key in the request, or the request carried none. |
API Key 无效或无权限 (English UI: API Key is invalid or lacks permission) | CC Switch v4.0.47, when its Fetch Models request gets HTTP 401 or 403 (source checked 2026-12-04). | The model-list request was refused. Put the same key in ROUTER_ONE_API_KEY and run the key check below. |
invalid_api_key and other spellings | Depends on the service and the client. | Read it with the HTTP status and the host your client called; the text alone does not say which server refused the key. |
Read the host before the message
A 401 is about the key that reached one particular server. Find that server first: the base URL set in your client, or the URL printed with the error. A relay, proxy or local tool between your client and the API can return its own 401 or show the text of the server behind it, so the wording alone does not prove which server refused the key.
| Host your client called | What a 401 there means | What to do |
|---|---|---|
api.router.one | Router One's key check refused the key, or the request carried none. | Use a key from Dashboard → API Keys and work through the causes below. |
Another service's host, such as api.openai.com | That service did not accept the key it received. A Router One key is not a key for that service. | Use that service's own key there, or point the client's base URL at Router One if you meant to use your Router One key. |
| A relay, proxy or local tool in between | The 401 can come from that layer or from the server behind it. | Check that layer's own key setting and the address it sends requests to. |
- Router One's base URL is
https://api.router.one/v1for OpenAI-compatible SDKs and tools, andhttps://api.router.one, without/v1, for Claude Code and other Anthropic-compatible clients.
Router One's 401, 402 and 403 side by side
Only a 401 means the key itself was not accepted. A valid key can still be refused with a 402 or a 403, and those need different fixes. Requests that get the 401, the 402 for funds or a key's limits, or the 403 from a key's model allowlist are refused before any model is called and leave no row in Dashboard → Logs, so keep the X-Request-ID response header and any request_id in the error body.
| Status | What was checked | Type and code | What to do |
|---|---|---|---|
| 401 | The key: missing, written wrongly, unknown, deleted, or past its Expiration Date | authentication_error, AUTH_INVALID_API_KEY; message invalid api key | Fix the header value, or create a new key in Dashboard → API Keys. |
| 402 | Money: the wallet balance, or this key's maxSpend or daily or monthly budget (both apply only to wallet-billed requests), cannot cover the request | billing_error; INSUFFICIENT_BALANCE, API_KEY_SPEND_CAP_EXCEEDED or API_KEY_PERIOD_BUDGET_EXCEEDED | Top up, or raise the key's maxSpend or budget in Dashboard → API Keys; a top-up does not raise either key limit. If money is left, a smaller request, or waiting for requests still running to finish, may be enough. |
| 403 | The key's model allowlist: the model is not on it, or the request used model="auto" | permission_error, API_KEY_MODEL_NOT_ALLOWED | Use a model on the allowlist (GET /v1/models with the same key lists them), or edit the allowlist in Dashboard → API Keys. |
- A 402 can come before the wallet balance, the key's
maxSpendor its budget is used up: a request is refused when what is left does not cover the minimum it has to reserve, and requests still running on the wallet or the key hold part of what is left until they settle. A smaller request may still go through, and letting running requests finish can clear the 402 without a top-up or a higher limit. - You can tell the causes apart by how the message starts: a 402 begins with
insufficient balance,api key spend cap reached,api key daily budget reachedorapi key monthly budget reached; an allowlist 403 begins withmodel "<id>" is not in this API key's model allowlistorauto routing is unavailable for an API key with a model allowlist. - On
/v1/messagesthe error body uses the Anthropic envelope ("type": "error"): the 403 carriescodethere, and a 402 whose message starts withinsufficient balanceorapi keydoes not, so read the message. - A 403 with the code
AUTH_FORBIDDENmeans the key may not perform that action (API reference).
Common causes of a 401 with a Router One key
Check these in order. The first four are about where the key went and what was sent, not about the key in the dashboard:
- The base URL points somewhere else. The client still calls another service or a mistyped host, so the key goes to a server that never issued it. Set
https://api.router.one/v1, orhttps://api.router.onefor Claude Code, in the field your client uses for the base URL. - The header value is written wrong. It should be
Bearer, one space, then the key. Common breakages:Bearer Bearer sk-…, because the client addsBearerand the variable already contains it; quotes pasted together with the key; a space inside the key;Authorization: sk-…with no scheme. A valid key sent in one of these forms still gets a 401. A line break inside the key is a different case, because an HTTP header cannot carry one: per Claude Code's errors reference (checked 2026-12-04), Claude Code stops such a request before anything is sent and names the variable to fix. Set that variable again without the line break. - The header is empty or holds the wrong token. An empty
Authorizationheader, an emptyx-api-keywithAuthorizationmissing, or a dashboard session token (a JWT) sent instead of an API key all get a 401. - The tool reads a different variable, or an old value. The key is set in another shell or profile file than the one that starts your tool, the tool reads another variable name, or the program was started before you changed the variable and still sends the old key.
- The key was deleted or has expired. Both return 401: check Dashboard → API Keys and create a new key if needed. An expired key you have not deleted still counts toward the active-key limit.
- It is not a Router One key. A key from another service, such as an OpenAI API key, gets a 401 on Router One; create a key in Dashboard → API Keys.
Check the key in one line
Router One's API reference documents GET /v1/models with a 401 for an invalid or missing API key, and the request calls no model, so it tests the key on its own. Run it in the shell that starts your tool. The command reads the key from ROUTER_ONE_API_KEY: set that variable to the key you want to test, or replace ROUTER_ONE_API_KEY in the command with the variable your tool reads (in Router One's Claude Code setup that is ANTHROPIC_AUTH_TOKEN). If the variable is empty or not set, the request carries no key and gets a 401 too. It prints only the HTTP status: 200 means the key was accepted, 401 that it was not.
curl -s -o /dev/null -w "%{http_code}\n" https://api.router.one/v1/models -H "Authorization: Bearer $ROUTER_ONE_API_KEY"
# Windows PowerShell:
curl.exe -s -o NUL -w "%{http_code}" https://api.router.one/v1/models -H "Authorization: Bearer $env:ROUTER_ONE_API_KEY"- A 200 does not rule out a 402 or a 403 on a model call: the wallet or the key's budget can still fall short, and a key with a model allowlist can still be refused a model that is not on it. With an allowlist,
GET /v1/modelslists only the models on it. - Keep the key out of screenshots, tickets and chats. If you write to support@router.one, send the time of the error and the request id, never the key itself.
CC Switch: API Key is invalid or lacks permission
Per CC Switch's v4.0.47 source (checked 2026-12-04), the Fetch Models button in its provider form shows API Key is invalid or lacks permission (Chinese UI: API Key 无效或无权限) when the model-list request gets HTTP 401 or HTTP 403, or an error that carries API_KEY_INVALID; HTTP 404 or 405 shows a different message, which starts No reachable models endpoint found. The request goes to {Base URL}/v1/models, or to {Base URL}/models when the Base URL already ends in a version such as /v1. The toast tells you the request was refused, not why.
- Put the key you pasted into CC Switch in
ROUTER_ONE_API_KEYand run the key check above. If it prints 401, fix the key as described on this page. - If it prints 200, the key is accepted and the difference is in how the provider is set up: compare its base URL and settings with the CC Switch guide (https://router.one/docs/guides/cc-switch).
- The same source notes that endpoints behind a firewall answered requests without a User-Agent with 403, which showed up as this toast (issue #7427); the model-list request now sends
cc-switchas a fallback User-Agent.
Claude Code, Codex and other clients
Client-specific guides:
- Claude Code: its own sign-in and key messages, and where it reads the key from, are on the Claude Code 401 & 403 page (https://router.one/claude-code-403).
- Codex:
unexpected status 401 UnauthorizedandMissing environment variable, including how to read the url on Codex's 401 line, are on the Codex 401 page (https://router.one/codex-401-unauthorized). - CC Switch: the values for Claude Code and Codex are in the CC Switch guide (https://router.one/docs/guides/cc-switch).
- OpenClaw and other tools: each integration guide names the fields that take the base URL and the key. OpenClaw's is at https://router.one/integrations/openclaw, the others at https://router.one/integrations.
FAQ
Is Incorrect API key provided a Router One error?
Router One's API reference gives invalid api key as the message of its own 401, with the code AUTH_INVALID_API_KEY and the type authentication_error. Incorrect API key provided is the OpenAI API's wording, per OpenAI's error-codes guide (checked 2026-12-04). Relays and clients can show another server's text, so check which host your client called before you decide which key to fix.
What does invalid_api_key mean?
It says, in the form of a code, that the server did not accept the key it received. Which server that was is not part of the text: read it with the HTTP status and the host your client called. On Router One the same case is HTTP 401 with the code AUTH_INVALID_API_KEY and the message invalid api key.
My key is correct. Why do I still get 401?
Usually the value that arrives is not the key you checked: the variable is set in another shell or profile file, the tool reads a different variable, a program started before the change still sends the old key, or the header carries Bearer twice, quotes, or a space inside the key. Run the key check on this page in the shell that starts your tool, without printing the key.
Will topping up fix a 401?
No. A 401 is about the key. On Router One, money problems return 402 instead: the wallet balance, or the key's maxSpend or daily or monthly budget, cannot cover the request. Topping up the wallet does not raise a key's maxSpend or budget; raise those in Dashboard → API Keys.
I get 403, not 401. Is my key wrong?
No. On Router One a deleted, expired or unknown key returns 401, not 403. A 403 with API_KEY_MODEL_NOT_ALLOWED means the key works but its model allowlist does not include the model you asked for, or the request used model="auto"; GET /v1/models with the same key lists the models it can call.
What does CC Switch's "API Key is invalid or lacks permission" (Chinese UI: "API Key 无效或 无权限") mean?
Per CC Switch's v4.0.47 source (checked 2026-12-04), its Fetch Models button shows it when the model-list request gets HTTP 401 or 403, or an error that carries API_KEY_INVALID. Put the key you pasted into CC Switch in ROUTER_ONE_API_KEY and run this page's key check: 401 means fix the key; 200 means the key is accepted, so compare the provider's base URL and settings with the CC Switch guide.
Does a 401 show up in Dashboard → Logs?
No. Router One refuses such requests before any model is called, so there is no row. Keep the X-Request-ID response header and any request_id in the error body. If the key keeps being refused, write to support@router.one with the time of the error and the request id, never the key itself.
I deleted a leaked key. What happens to calls that still use it?
New requests with it return HTTP 401; requests already in flight still finish and settle. Create a new key in Dashboard → API Keys and replace the old value everywhere it is set.
Which base URL should my client use?
https://api.router.one/v1 for OpenAI-compatible SDKs and tools, and https://api.router.one, without /v1, for Claude Code and other Anthropic-compatible clients. A key sent to any other host is checked by that host, not by Router One.