← Documentation

Error handling

/api/v1/chat/completions and /api/v1/models return errors in OpenAI format:

{
  "error": {
    "message": "Insufficient credits (balance: 0.00). Buy more credits or wait for your next billing cycle.",
    "type": "invalid_request_error",
    "code": "insufficient_credits",
    "param": null
  }
}

/api/v1/messages and /api/v1/messages/count_tokens return the Anthropic format:

{
  "type": "error",
  "error": {
    "type": "authentication_error",
    "message": "Invalid API key. Create one in your TokRouter settings."
  }
}

HTTP status codes

HTTPcode (OpenAI)type (Anthropic)Cause
400invalid_requestinvalid_request_errorInvalid JSON body, or missing model/messages
400message_too_longinvalid_request_errorMessage too long for the free tier
401invalid_api_keyauthentication_errorAPI key missing, invalid, or revoked
402insufficient_creditsCredit balance exhausted (≤ 0)
403subscription_requiredModel reserved for subscribers or credit holders
404model_not_foundnot_found_errorUnknown or disabled model identifier
429rate_limit_exceededrate_limit_errorPer-API-key rate limit exceeded
429daily_limit_reachedinvalid_request_errorFree-tier daily limit reached
502upstream_auth_errorapi_errorServer-side configuration error on TokRouter's end (not your key)
provider-dependentupstream_errorapi_errorThe model provider returned an error; the HTTP code passed through is theirs

What never happens

  • A failed request never charges your credits: billing only happens after a successful response containing the exact usage (see Credits and billing).
  • A 401/403 error from the model provider (misconfiguration on TokRouter's side) is never presented to you as a problem with your API key: it always returns 502 with upstream_auth_error / api_error.
  • There is no automatic fallback to another model yet when a provider errors: the request simply fails with the code above.

Rate limiting

Every response (success or error) includes the X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset headers. A 429 error also adds Retry-After (seconds until the next window).