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.
{
"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:
{
"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:
{
"async": {
"enabled": true,
"tags": ["nightly-report", "customer-42"],
"webhooks": ["https://example.com/hooks/async-generations"],
"timeout": 300
}
}| Field | Description |
|---|---|
enabled | Set to true to queue the request. |
tags | Up to 16 labels, each 1–64 characters. Use them to find items later. |
webhooks | Up to 4 public HTTP or HTTPS URLs notified when the item is done. See Webhooks. |
timeout | Seconds 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 #
asynccannot be combined withstream: true; the request fails with400.- 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:
| Product | Endpoint |
|---|---|
| Chat completions | POST /v1/chat/completions |
| Responses and Messages | POST /v1/responses, POST /v1/messages |
| Semantic decisions | POST /api/v1/generations/decisions |
| Extraction | POST /api/v1/generations/extract |
| Summarization | POST /api/v1/generations/summarize |
| Translations | POST /api/v1/generations/translate |
| Text segmentation | POST /api/v1/generations/segment |
| Text classification | POST /api/v1/generations/classify |
| Image generation | POST /api/v1/generations/images |
| Speech-to-text | POST /api/v1/generations/audio/transcriptions |
| Text-to-speech | POST /api/v1/generations/speech |
| Agentic Tests | POST /api/v1/generations/agentic-tests |
| Rerankers | POST /api/v1/generations/rerank |
| Web Search | POST /api/v1/web/search |
| Fetch and OCR | POST /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:
| Status | Meaning |
|---|---|
pending | Queued and waiting to run. |
retrying | A previous attempt failed with a retryable error and another attempt is scheduled. |
processing | Running now. |
done | Finished. The stored result may be a success or an error; check its status code. |
cancelled | Cancelled 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
timeoutis stored with status408and 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:
| Item | Deleted |
|---|---|
pending or retrying | 15 days after creation. |
cancelled | 1 hour after cancellation. |
done | 90 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:
{
"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.
| Request | Description |
|---|---|
GET /api/v1/async-generations | Lists 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>/response | Returns 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>/cancel | Cancels 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:
GET /api/v1/async-generations?status=done&tags=nightly-report&limit=100Reduce 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:
{
"model": "@openai/gpt-6-luna",
"routing_options": { "preset": "Fastest" },
"messages": [{ "role": "user", "content": "Classify this ticket." }],
"async": { "enabled": true, "tags": ["triage"] }
}