AIVAX

Async Generations

Async generations queue a single API request and run it in the background. Instead of keeping a connection open until the result is ready, you receive an ID, and then fetch the stored result later or let AIVAX notify your service when it is done.

Use async generations when one request is slow, when a caller cannot hold a connection open, or when many independent requests should run without client-side concurrency control. Use Batch workflows when the same instruction should be applied to a list of inputs with validation, retries, and export.

Queue a request #

Add async to the body of any supported request. The rest of the body is the same as the synchronous request.

JSON
{
  "model": "@openai/gpt-6-luna#cheapest",
  "messages": [{ "role": "user", "content": "Summarize this report." }],
  "async": true
}

Nothing is generated while the request is open. AIVAX validates it, queues it, and returns HTTP 202:

JSON
{
  "message": "The generation was queued.",
  "data": {
    "async_generation": {
      "id": "<generation-id>",
      "status": "pending"
    }
  }
}

Keep the id: it identifies the item in the management API.

Options #

Use the object form to tag the item, register webhooks, or change the timeout:

JSON
{
  "async": {
    "enabled": true,
    "tags": ["nightly-report", "customer-42"],
    "webhooks": ["https://example.com/hooks/async-generations"],
    "timeout": 300
  }
}
FieldDescription
enabledSet to true to queue the request.
tagsUp to 16 labels, each 1–64 characters. Use them to find items later.
webhooksUp to 4 public HTTP or HTTPS URLs notified when the item is done. See Webhooks.
timeoutSeconds allowed for each execution attempt, from 10 to 3,600. The default is 3,600.

"async": true is the same as { "enabled": true }. Tags can also be sent as a top-level async_tags array.

Restrictions #

  • async cannot be combined with stream: true; the request fails with 400.
  • Queuing is not available with public API keys.
  • An account can turn the feature off with the Async generations account parameter, which is on by default. While it is off, queuing requests fail with 403, and items already queued wait until it is turned back on.
  • Each plan limits how many items an account can queue per hour. See Batch and Agentic Tests limits.

Supported endpoints #

The same async field works on these requests:

ProductEndpoint
Chat completionsPOST /v1/chat/completions
Responses and MessagesPOST /v1/responses, POST /v1/messages
Semantic decisionsPOST /api/v1/generations/decisions
ExtractionPOST /api/v1/generations/extract
SummarizationPOST /api/v1/generations/summarize
TranslationsPOST /api/v1/generations/translate
Text segmentationPOST /api/v1/generations/segment
Text classificationPOST /api/v1/generations/classify
Image generationPOST /api/v1/generations/images
Speech-to-textPOST /api/v1/generations/audio/transcriptions
Text-to-speechPOST /api/v1/generations/speech
Agentic TestsPOST /api/v1/generations/agentic-tests
RerankersPOST /api/v1/generations/rerank
Web SearchPOST /api/v1/web/search
Fetch and OCRPOST /api/v1/web/fetch

How an item runs #

Queued items run in the order they were queued.

When an item runs, AIVAX executes the original request exactly as sent: the same endpoint and the same body. The result is stored with the original HTTP status code, content type, and cost, so a failed generation is stored as a failed result rather than as a platform error.

An item moves through these statuses:

StatusMeaning
pendingQueued and waiting to run.
retryingA previous attempt failed with a retryable error and another attempt is scheduled.
processingRunning now.
doneFinished. The stored result may be a success or an error; check its status code.
cancelledCancelled by you. It will not run again.

Retries #

These failures are retried up to 3 times:

  • insufficient balance;
  • rate limiting;
  • service unavailable or other server errors (5xx).

When the retries run out, the item finishes as done with the error status code of the last attempt. Keep the account balance topped up before queuing large amounts of work.

Other outcomes are final:

  • An attempt that exceeds its timeout is stored with status 408 and is not retried.
  • A response larger than 12 MB is not stored; the item finishes with status 507.
  • When the API key that queued the item was deleted or expired before the item ran, the item finishes with status 401.

Retention #

Items are deleted automatically:

ItemDeleted
pending or retrying15 days after creation.
cancelled1 hour after cancellation.
done90 days after completion.

Fetch and store the results you need before they expire.

Webhooks #

When an item reaches done, AIVAX sends a POST request with a JSON body to each URL in webhooks:

JSON
{
  "id": "<generation-id>",
  "status": "done"
}

The notification carries no result and no outcome, so done also covers a stored error. Use the id to fetch the result with your API key, and check its status code.

Webhook URLs must be public HTTP or HTTPS URLs. When the account has a hook key, each request includes X-Request-Nonce; verify it as described in Hook authentication before trusting the notification.

Delivery is not retried. If your service can be unavailable, also poll the list endpoint for done items.

For a Python example that collects results by tag, re-queues only the failures, and verifies the webhook nonce, see Async LLM API: queue the request, get an ID, fetch the result later.

Manage queued generations #

Authenticate management requests with an AIVAX API key. All routes are under /api/v1/async-generations.

RequestDescription
GET /api/v1/async-generationsLists items as summaries, without request or response bodies. Filter with status, tags (comma-separated; an item must have all of them), limit (default 50, maximum 100), and offset.
GET /api/v1/async-generations/<id>Returns the item with its request and response. JSON bodies are embedded as JSON; other content is returned as base64.
GET /api/v1/async-generations/<id>/responseReturns the stored response as it was produced, with its original status code and content type. Use it to consume the result as if the request had been synchronous.
PUT /api/v1/async-generations/<id>/cancelCancels an item that is pending, retrying, or done with an error status code. Any other item returns 409.
PUT /api/v1/async-generations/cancel?scope=<scope>Cancels in bulk. scope is pending, failed, or all.
DELETE /api/v1/async-generations/<id>Deletes an item. Returns 409 while it is processing.

For example, to list the finished items tagged for a nightly job:

TEXT
GET /api/v1/async-generations?status=done&tags=nightly-report&limit=100

Reduce cost #

Queued work rarely needs the fastest provider, so async generations use the Cheapest routing preference by default. To favor speed or quality for a queued item, set the preference explicitly with routing_options.preset or a model name suffix:

JSON
{
  "model": "@openai/gpt-6-luna",
  "routing_options": { "preset": "Fastest" },
  "messages": [{ "role": "user", "content": "Classify this ticket." }],
  "async": { "enabled": true, "tags": ["triage"] }
}

Type to search the documentation.