Skip to content

API reference

Errors

The OpenAI error envelope, every Cairva product code, its HTTP status and what to do about it.

On this page

Gateway errors use the OpenAI error envelope, so OpenAI SDKs raise them as normal API errors. Branch on code: it's a stable Cairva product code. The message is for people and can change.

JSON
{
  "error": {
    "message": "allocation_exhausted: 120 input and 0 output tokens remain",
    "type": "invalid_request_error",
    "code": "allocation_exhausted"
  }
}

type follows the status: authentication_error for 401, rate_limit_error for 429, api_error for 5xx, and invalid_request_error for everything else.

Codes

StatusCodeWhen it happensWhat to do
400validation_failedThe body isn't JSON, or a field fails validation. The message names the fieldFix the request. See Chat completions
401unauthenticatedThe key is missing, malformed, unknown or revokedCheck the key. See Authentication
402allocation_exhaustedNot enough input or output allowance remains to admit this request. The message says what's leftShorten the prompt, wait for running requests to settle, or buy more capacity
402allocation_depletedThe allocation used its full allowance and closedBuy more capacity
403scope_missingThe key doesn't have the scope this endpoint needsUse a key with inference or usage:read
403key_unscopedThe key isn't bound to an allocationCreate a key for an allocation
403model_not_permittedmodel isn't the one model this key's allocation covers. The message names itUse the id from GET /v1/models
403allocation_reservedThe agreement behind the allocation hasn't activated yetWait for activation
403allocation_not_startedThe window hasn't opened. The message includes the start timeRetry after the start time
403allocation_expiredThe delivery window has endedBuy new capacity
403allocation_pausedThe supplier or operations paused the allocation. The message carries the reason when one was givenRead the reason in the workspace
403allocation_terminatedThe allocation was terminated and won't serve more requestsBuy new capacity
429rate_limitedA requests-per-minute, tokens-per-minute or concurrency limit was hitWait for Retry-After seconds. See Rate limits
502upstream_errorThe provider didn't complete the request. The hold is released and nothing is chargedRetry with backoff
502route_disabledOperations paused the route behind this allocationCheck the status page
502route_unconfiguredThe route has no provider credentials configuredContact Cairva
500internal_errorSomething failed inside CairvaRetry with backoff. Quote the request id if it persists

Retry-After

Every 429 carries a Retry-After header in seconds: 60 for the requests-per-minute and tokens-per-minute limits, 2 for the concurrency limit. The OpenAI SDKs read it when they retry.

Retrying safely

A request that failed never consumes allowance. Its hold is released when Cairva records the failure. Retrying a 502 upstream_error or a 429 can't double-charge you.

4xx codes other than 429 won't succeed on retry without a change: a new key, a different model, or a new allocation.

Errors inside a stream

A failure after a stream has opened arrives as one event, {"error": {"code": "upstream_error", "message": "..."}}, and then the stream closes. See Streaming.