Published November 14, 2026 · 6 min read
Fixing 401 and 402 Errors from the zrouter API: invalid_api_key, insufficient_balance and key_daily_limit_reached
What 401 invalid_api_key and 402 insufficient_balance or key_daily_limit_reached mean on the zrouter API, the usual causes, and a short checklist to fix each one.
Two status codes cause most first-day support questions on any API gateway: 401 and 402. They mean very different things, and the fix for one is useless for the other. This guide explains both as zrouter's gateway behaves today, with a checklist for each.
The short version
| Status | code | What it means | What to do |
| --- | --- | --- | --- |
| 401 | invalid_api_key | The gateway does not accept the credentials you sent | Fix the key or how it is sent |
| 402 | insufficient_balance | The key is valid, but your Token Plan and pay-as-you-go balance cannot cover the request | Top up, or buy a Token Plan for the model |
| 402 | key_daily_limit_reached | The key is valid and funded, but it reached its own daily spend limit | Wait for the reset at 00:00 UTC, or raise the limit |
Neither is worth retrying in a loop. A 402 will not fix itself until you add funds or the day rolls over, and a 401 will not fix itself until you change the credentials.
What the response looks like
On /v1/chat/completions and /v1/responses the error uses the OpenAI-shaped envelope:
{
"error": {
"message": "Insufficient balance. Top up PAYG credit or buy a Token Plan for this model.",
"type": "billing_error",
"code": "insufficient_balance",
"request_id": "req_..."
}
}
On /v1/messages the same information is wrapped in the Anthropic-shaped envelope, with "type": "error" at the top. Branch on code, which is stable, rather than on the message text. The error reference lists every code.
Fixing 401 invalid_api_key
The gateway answers a 401 identically for a missing key, a wrong key, a revoked or expired key, a blocked account, and for requests that carry two authentication headers with different values. That is deliberate: it stops anyone from using the response to learn whether a key exists. It also means you have to find the cause yourself. Work through this list:
- Is the key actually being sent? Keys look like
zr_<id>_<secret>. BothAuthorization: Bearer <key>andx-api-key: <key>work. Print the variable in the same shell that runs your tool (for exampleecho ${#ZROUTER_API_KEY}shows its length) to confirm it is set. - Hidden characters. A trailing newline or space copied along with the key is a classic cause. Re-paste the key, or store it with
printf %s. - Two headers that disagree. If a tool sends both
Authorizationandx-api-key, they must carry the same key. Claude Code is a common case: setting bothANTHROPIC_AUTH_TOKENandANTHROPIC_API_KEYto different values produces exactly this. Set only one. See running DeepSeek or GLM in Claude Code. - Revoked or expired key. Check the key list in the dashboard. A key shown only once cannot be recovered: if you lost it, create a new one and update your tools.
- Copied the wrong thing. The key secret is revealed once when you create it. A key ID or a key from another provider will not work.
- Blocked account. A blocked account gets the same
401. If everything above checks out, contact support.
A wrong base URL does not give a 401. A path that does not exist returns 404, so if you see 404, check the URL and the model name first.
Fixing 402 insufficient_balance
A 402 insufficient_balance means the key is valid but the request cannot be paid for. Requests are paid in a fixed order: the Token Plan for that model first, then your pay-as-you-go balance. If neither can cover the request, the gateway rejects it before any inference runs, so you are not charged.
What to check:
- Is it the right balance? A Token Plan is per model. A plan for one model does not pay for another, and then your pay-as-you-go balance must cover it. The pay-as-you-go balance is shared across all models.
- Is the pay-as-you-go balance empty? A request that has to be paid from the balance is refused when the balance is zero or negative. Top up. A request that a Token Plan with remaining tokens can pay for is still allowed even when the pay-as-you-go balance is empty.
- Did a recent top-up land? QRIS top-ups are credited once the payment is confirmed. Crypto top-ups are credited once the transaction is finalized on-chain, which is usually within a minute. If the dashboard balance has not changed, check the order status on the checkout page before paying again.
- Is a parallel job draining it? Several agents or scripts on the same account share one balance. Check the usage page for the requests that spent it.
Then retry once. Do not loop on a 402.
Fixing 402 key_daily_limit_reached
This one looks like a billing error but the account has money. The key itself has a daily spend limit, and it reached that limit for the current UTC day. The message says so: "Daily spend limit reached for this API key. It resets at 00:00 UTC", which is 07:00 in Jakarta.
- Wait for the reset, or raise or remove the limit on that key in the dashboard.
- Other keys on the account keep working, because the limit applies per key.
- The limit counts the displayed cost of requests paid from a Token Plan as well as from the balance.
The full explanation, with an example, is in the Indonesian guide on per-key daily limits.
Test it without your tool
When a tool hides the details, take it out of the loop:
curl -i https://api.zrouter.dev/v1/chat/completions \
-H "Authorization: Bearer $ZROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"deepseek-v4.1-flash","messages":[{"role":"user","content":"Hello"}],"max_tokens":512}'
A 200 means the key and funding are fine and the problem is in your tool's configuration. A 401 or 402 here points straight at the key or the balance, and the code tells you which.
Paying
Top up with QRIS, USDT or USDC, with no credit card. QRIS checkouts can include a small service fee that is shown before you pay; for USDT and USDC the sender pays the blockchain network fee, which is not part of the zrouter price. See the pricing page for Token Plan tiers.