Command Palette

Search for a command to run...

Errors

The error object, every code the API returns with its status, which failures are worth a retry, and the five-minute checks that resolve most first refusals.

The shape

A refusal from the API itself returns an OpenAI-style error object with an HTTP status. The status is the coarse signal, `error.type` is the class of failure, and `error.code` is the stable, machine-readable reason — branch on the code, not on the message, because the message is written for a human and may be reworded.

Example
{  "error": {    "message": "Your balance is empty. Top up to continue.",    "type": "insufficient_quota",    "code": "no_balance"  }}

`error.type` is one of `authentication_error`, `invalid_request_error`, `insufficient_quota`, `rate_limit_error` or `upstream_error`. A refusal produced here writes no usage row and charges nothing: the request never reached a provider.

Every code the API returns

CodeStatusWhen you see it
invalid_api_key401No Authorization header, a scheme other than Bearer, a malformed key, or a key that is unknown, revoked, or whose account is inactive.
endpoint_not_found404A path outside models, chat/completions, completions and embeddings — including any path containing a . or .. segment.
method_not_allowed405GET on anything but /v1/models; the forwarded inference paths take POST.
invalid_json400The request body is not parseable JSON.
body_too_large413The body is above the size cap — 1000 KB by default.
model_required400The model field is missing, empty, or not a string.
model_not_found400The id is not in the catalogue, or the model is not published right now.
model_unpriced400The model is published but has no price, so it cannot be billed.
no_balance402The balance is at or below zero. Nothing was sent to a provider.
spend_limit402A rolling spend limit was reached; the message names the window (daily, weekly, monthly).
too_many_pending429Too many requests for this account are admitted and not yet billed — 100 by default. Wait for them to settle and retry.
gateway_unreachable502The upstream could not be reached. The reservation was released and nothing was charged.

Provider errors are not in this table

When a provider answers with a non-2xx status, the response is relayed with the provider's own status and body. That body may not be the error object above, and its code belongs to the provider, not to this API. Read the status first, then the body.

A provider error can still be billed. If the provider produced tokens before failing — a mid-stream cut, a timeout after generation — that usage exists in the gateway log, so it is a real charge rather than a refusal.

Retrying

  • 4xx — fix the cause. These will not succeed on their own, however many times you retry.
  • 429 — wait. The requests in front of yours are being billed; retry with backoff rather than in a tight loop.
  • 502 — safe to retry, because the reservation was released and nothing was charged.
  • A provider 5xx relayed through — retry only with backoff, and expect that the failed attempt may have been billed if it produced tokens.

Five checks that resolve most refusals

  • The key: echo the variable's length, not its value. An unset variable produces an empty bearer token and a 401.
  • The header: it must be `Authorization: Bearer <key>`, with one space and no quotes around the key.
  • The URL: exactly one `/v1`, on the `api.` host, with the operation in the path and the model in the body.
  • The id: compare it character for character with `GET /v1/models`; an id from elsewhere will be refused even if it is a real model.
  • The method: `/v1/models` is a GET; chat, completions and embeddings are POST.

If those five are right, `curl -i` the same request and read the status line and the body together — the Quickstart has a working example of each, and the Pricing page explains the gate a `402` came from.