Skip to content

Errors

Every error code the Tokens API returns, what it means and what to do, plus the error JSON shape, request ids for support tickets, and which errors to retry.

On this page

This page lists every API error code the Tokens gateway returns, what each one means, and whether to retry. Branch on the code field in your code; messages are for humans and can change.

Error JSON shape#

Errors raised by the gateway look like OpenAI's:

json
{
  "error": {
    "message": "Prepaid wallet balance is insufficient for this request. Top up your wallet in the dashboard: https://tokens.bd/dashboard/billing",
    "type": "insufficient_quota",
    "code": "insufficient_credits",
    "param": null,
    "request_id": "8f0c7a4e-2b1d-4c55-9a51-3f7e2d9b6c10"
  }
}
FieldNotes
codeStable, machine-readable. Use this.
typeBroad class: authentication_error, permission_denied_error, insufficient_quota, rate_limit_error, invalid_request_error, api_error, server_error or tokens_error.
messageHuman-readable. Billing errors include a link to billing.
request_idSame value as the x-tokens-request-id header. Missing on unsupported_endpoint; use the header there.

On /v1/messages, errors from the upstream provider use Anthropic's shape instead, {"type": "error", "error": {"type": "...", "message": "..."}}, while gateway errors keep the shape above. Upstream error messages are replaced with a generic message so provider internals don't leak; the HTTP status and code still tell you the category.

Error code reference#

StatusCodeMeaningWhat to do
400invalid_requestMissing model (or no Content-Type: application/json), n outside 1 to 4, or the upstream rejected the request bodyFix the request. For upstream rejections, check the model supports the parameters you sent
400model_not_availableThe model is in the catalog but can't be served right nowPick another model from GET /v1/models
401missing_api_keyNo Authorization: Bearer or x-api-key headerSet TOKENS_API_KEY in the environment that runs the tool
401invalid_api_keyKey not recognizedRecopy the key or create a new one
401/403upstream_auth_errorThe upstream provider refused the gateway's credentials. Not your keyRetry later or switch model; report it with the request id
402insufficient_creditsPlan credits and wallet can't cover the requestTop up or renew in billing, or lower max_tokens
402no_fundingNo active plan and no wallet balanceSubscribe or add funds
402outstanding_debtEarlier usage left a negative balanceTop up to clear it
402member_cap_reachedTeam accounts (if enabled): your member monthly cap is reachedAsk your team admin
403key_inactiveKey revoked or rotatedUse the current secret
403key_expiredKey past its expiry dateCreate a new key
403account_suspendedAccount suspendedContact support
403model_not_allowed_on_keyModel not in this key's allowed listUse an allowed model or another key
403monthly_spend_cap_exceededKey's monthly spend cap reached (the check includes this request's worst-case cost)Lower max_tokens, wait for the new month, or use another key
403tier_permission_deniedYour plan doesn't include this model and you have no wallet balanceUpgrade, or add wallet funds for pay-as-you-go
404model_not_foundModel id unknown or inactive (also returned when the upstream doesn't know the model)Check the exact id with GET /v1/models
404unsupported_endpointPath or method isn't one of the supported endpointsSee models and usage for the endpoint list
413request_entity_too_largeBody over 10 MBTrim context or attachments
429rate_limitedRequests-per-minute limit reachedWait Retry-After seconds
429concurrency_limitToo many requests in flight on your accountWait Retry-After (2 s) or reduce parallelism
429window_exhaustedA plan usage window (5-hour, weekly or monthly) is used upWait for the reset (Retry-After) or upgrade the plan
429rate_limit_exceededThe upstream provider rate limited us after failover was exhaustedRetry with backoff; honor Retry-After if present
500lookup_failed, admission_error, catalog_error, usage_unavailableInternal error on our sideRetry once or twice with backoff, then contact support
502upstream_unreachableCouldn't connect to any upstream for this modelRetry with backoff; check status
5xxupstream_errorThe upstream returned a server error (status passed through)Retry with backoff
503no_upstream_availableNo upstream is configured for this model right nowTry another model; check status
503model_not_pricedThe model has no price configured, so it can't be billedTry another model and report it
504upstream_timeoutUpstream didn't respond within 600 s, or the connection broke after the request was sentRetry once; consider a smaller request

The gateway already fails over to another upstream source on 429, 502, 503, 504 and connection errors before returning anything to you. An upstream error you see means every configured source for that model failed or the last one did.

Request ids and support tickets#

Every response, success or error, carries two headers:

HeaderValue
x-tokens-request-idThe gateway's id for this request. Always generated by us.
x-request-idYour own x-request-id if you sent one, otherwise the same as x-tokens-request-id

Sending your own x-request-id lets you correlate our id with your logs. To read the header with the OpenAI Python SDK:

python
raw = client.chat.completions.with_raw_response.create(
    model="deepseek/deepseek-v4.1-flash",
    messages=[{"role": "user", "content": "ping"}],
)
print(raw.headers.get("x-tokens-request-id"))
completion = raw.parse()

With curl, add -i to print headers. When you open a ticket in support, include the x-tokens-request-id, the time (with timezone), the endpoint, the model and the status code. Never include the API key. We store usage metadata by request id, not prompt content, so the id is what lets us find your request. More in support.

Retry guidance#

RetryCodes
Yes, after Retry-Afterrate_limited, concurrency_limit, rate_limit_exceeded
Yes, with exponential backoffupstream_unreachable, upstream_error, upstream_timeout, all 500s
Only after the reset time, not in a loopwindow_exhausted (Retry-After can be hours)
No, fix something firstAll 400, 401, 402, 403, 404 and 413 errors

Backoff that works in practice: start around 1 second, double each attempt, add random jitter, cap at 30 seconds, and stop after 4 or 5 attempts. If Retry-After is present, wait at least that long. A retry is a new request and is billed if it succeeds, and the OpenAI and Anthropic SDKs already retry some of these errors on their own, so check max_retries before stacking your own loop on top. A full backoff example is in rate limits, and agent-specific fixes are in troubleshooting.

Was this page helpful?

Still stuck? Open a support ticket

Need help configuring your agent?

Test your connection with the connection tester, or create an API key.