Errors

Error response shapes and error codes for the Tokener.ai model API.

Updated 2026-07-14
Edit on GitHub

Every model API response — success or error — carries x-request-id and request-id response headers (req_<32 hex chars>). Include the value when contacting support.

Non-streaming errors

Errors are returned with a non-2xx HTTP status and a JSON body. The shape matches the request's protocol.

OpenAI-shaped paths (/models, /chat/completions, /embeddings, /responses):

{
  "error": {
    "message": "Invalid API key.",
    "type": "authentication_error",
    "param": null,
    "code": "invalid_api_key"
  }
}

Anthropic-shaped path (/messages):

{
  "type": "error",
  "error": {
    "type": "authentication_error",
    "message": "Invalid API key."
  },
  "request_id": "req_1f2e3d4c5b6a7988a1b2c3d4e5f60718"
}

Streaming errors

When stream: true and an error occurs after the stream has already started, the error arrives as one SSE frame instead of an HTTP error status. There are three shapes, depending on the path:

/chat/completions (OpenAI Chat Completions):

data: {"error":{"message":"Upstream request failed.","type":"upstream_error","param":null,"code":"provider_error"}}
 

/messages (Anthropic Messages):

event: error
data: {"type":"error","error":{"type":"api_error","message":"Upstream request failed."},"request_id":"req_1f2e3d4c5b6a7988a1b2c3d4e5f60718"}
 

/responses (OpenAI Responses):

event: error
data: {"type":"error","code":"provider_error","message":"Upstream request failed.","param":null}
 

Error codes

code (OpenAI shape) and error.type (Anthropic shape) are stable and safe to branch on. message text is not — it may change without notice.

HTTP statuscodeOpenAI typeAnthropic typeMeaning
400invalid_requestinvalid_request_errorinvalid_request_errorMalformed request
401invalid_api_keyauthentication_errorauthentication_errorMissing or invalid API key
402insufficient_creditsbilling_errorbilling_errorPrepaid credit balance is too low
403permission_deniedpermission_errorpermission_errorKey lacks access to this model or route
404route_not_foundinvalid_request_errornot_found_errorUnknown path
404model_not_foundinvalid_request_errornot_found_errorModel id not found
405method_not_allowedinvalid_request_errorinvalid_request_errorWrong HTTP method for the path
413request_too_largeinvalid_request_errorrequest_too_largeRequest body exceeds the size limit
429rate_limit_exceededrate_limit_errorrate_limit_errorToo many requests; see the retry-after header
502provider_errorupstream_errorapi_errorUpstream provider request failed
503overloadedservice_unavailable_erroroverloaded_errorGateway in-flight limit reached; retry later
503gateway_unavailableservice_unavailable_errorapi_errorCould not reach the upstream
504upstream_timeouttimeout_errorapi_errorUpstream did not respond in time

SDK advice

Branch on code / error.type and HTTP status, never on message. Treat 4xx as generally non-retriable (except 429, which is retriable after retry-after) and 5xx (502/503/504) as retriable with backoff.