Errors & limits

Errors come back in a standard format: a status code and a text explanation. Below is what to do in each case.

Response codes

CodeWhat happenedWhat to do
401key not recognizedcheck the Authorization header and that the key hasn't been deleted
403not enough balance or the key's limit is reachedtop up your balance or raise the key's limit
404unknown model namecheck it against the model list
413request exceeds the context windowtrim the history or use a model with a larger context
429too many requests in a rowretry with a growing delay
5xxtemporary failure on the model's sideretry the request or switch to a fallback model

Retries

Only retry on 429 and 5xx, and always with a growing delay — otherwise the retries themselves add load.

async function ask(body, tries = 3) {
  for (let i = 0; i < tries; i++) {
    const res = await fetch(url, { method: "POST", headers, body: JSON.stringify(body) });
    if (res.ok) return res.json();
    if (![429, 500, 502, 503, 504].includes(res.status)) throw new Error(await res.text());
    await new Promise((r) => setTimeout(r, 500 * 2 ** i)); // delay grows
  }
  throw new Error("Service unavailable, try again later");
}

Limits

  • Per-key limit — you set it yourself when creating the key and can change it anytime.
  • Context window — different for each model, listed in the catalog.
  • Request rate — softly limited, ordinary apps never notice it.
If a key was issued from an activation code, its limit can't exceed the code's value. More details in the usage section.

What's next