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
| Code | What happened | What to do |
|---|---|---|
| 401 | key not recognized | check the Authorization header and that the key hasn't been deleted |
| 403 | not enough balance or the key's limit is reached | top up your balance or raise the key's limit |
| 404 | unknown model name | check it against the model list |
| 413 | request exceeds the context window | trim the history or use a model with a larger context |
| 429 | too many requests in a row | retry with a growing delay |
| 5xx | temporary failure on the model's side | retry 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.