Docs

API Reference

Errors & Retries

Errors & Retries

What the API returns when something goes wrong, and how to recover.

Error shape

Every error has the same envelope, whatever its cause. request_id is always present, and retry_after_ms appears when waiting will help.

json
{
  "error": {
    "type": "rate_limit_exceeded",
    "code": "rate_limit_exceeded",
    "message": "Too many requests.",
    "request_id": "req_...",
    "retry_after_ms": 12000
  }
}

Status codes

StatusMeaningWhat to do
400 / 422Something in the request is wrong. For 422, details names each field.Fix the request; don't retry unchanged.
401The API key is missing, invalid or expired.Check the X-API-Key header and that the key is Active on the API Keys page.
402Your credit balance is empty (code insufficient_credit).Add credit in AI Studio, then retry.
403The key isn't allowed to do this.Check the key and the endpoint.
413The request is too large.Send less, or fewer or smaller files.
429Too many requests, a quota was reached, or your own spend limit was (code spend_limit_reached).Wait for the Retry-After time, then retry. See below.
502Aivana couldn't complete the answer. You aren't charged for it.Safe to retry.
504The request took too long.Retry, possibly with a lower effort or a shorter request.

JSON Schema (Strict) errors

CodeStatusMeaningWhat to do
invalid_response_schema422Your schema is malformed or uses a feature Aivana doesn't support. It is refused before anything runs, and nothing is charged.Fix the schema; see Parameters. Retrying unchanged won't help.
structured_output_streaming_not_supported422A JSON Schema response was sent to the streaming endpoint.Use Generate instead.
structured_output_failed502Your schema was valid, but Aivana couldn't produce a response that matches it. You get an error rather than a response that doesn't match, and you aren't charged.A retry can succeed. If it keeps failing, loosen the schema (fewer constraints, nullable fields) or give the request more room with a higher max_tokens.

Rate limits

When your workspace sends requests or tokens faster than its limits allow, the API answers 429 with a Retry-After header (in seconds) and retry_after_ms in the body. What the limits are, how they rise, and how to see yours are on Rate Limits.

Your purchased credit spend limit

You can set a purchased credit spend limit on your account, and on each API key, on the Billing and API Keys pages. Choose a daily, weekly or monthly limit (all in UTC; a week runs Monday to Sunday; Monthly is the first choice offered). It protects you from a bug that sends requests in a loop. It counts only what you spend from purchased credit: usage paid for with promotional tokens is never limited and does not count. Once what you have spent from purchased credit in that period reaches it, the API answers 429 with the code spend_limit_reached and a Retry-After header counting down to when the period starts again: 00:00 UTC tomorrow, next Monday, or the 1st of the next month. Requests already running when the limit is reached still finish and are charged, so a period can end a little over it. Raise or remove the limit and requests are accepted again within a minute. Retrying sooner than Retry-After won't help. Only you can set the limit; Aivana never does.

Retrying

  • Retry only 429, 502 and 504, and network failures. Other 4xx errors won't succeed unchanged.
  • Wait for the time in Retry-After (or retry_after_ms) when it is given; otherwise back off exponentially, for example 1, 2, 4, then 8 seconds, with a little random jitter.
  • Stop after a few attempts and surface the error, with its request_id, to your user or logs.
  • A request that failed on Aivana's side isn't charged, so a retry doesn't cost you twice.
python
from aivana import RateLimitError, UpstreamError

try:
    res = aivana.generate("Summarize our Q3 churn drivers.")
except (RateLimitError, UpstreamError) as err:
    print("Retry later:", err.message, err.request_id)

Learn more

Managing API Keys

Learn how to create and revoke API keys in Aivana AI Studio.

Create KeyView in Docs

Quickstart Guide

Get your key and make your first request in minutes.

Parameters

Every option the Generate API accepts.

Still have questions? We are here to help!

Try live

Run chat interactively in the Playground without any setup.

On this page

Errors & RetriesError shapeStatus codesJSON Schema (Strict) errorsRate limitsYour purchased credit spend limitRetrying

Helpful links

Aivana Status

Was this helpful?

Still have questions? We are here to help!