Why Use the Async Queue
The synchronous endpoints (/ai/images/generate, /ai/videos/generate) block until the result is ready. For video generation, this can be 1-10+ minutes. The async queue returns immediately with generation IDs so you can:
- Generate up to 4 images or videos in parallel
- Avoid long-lived HTTP connections
- Build progress-tracking UIs
Workflow
Enqueue: POST /api/ai/queue
Submit an async image or video generation job.Request Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | yes | — | Must be an image or video model. Text-only models are rejected. |
prompt | string | one of | — | Text prompt. Use this or multi_prompt for video models. |
num_generations | integer | no | 1 | How many generations to run in parallel. Range: 1-4. |
target_namespace | string | no | your username | Namespace to store results and bill to. |
seed | integer | no | — | Random seed for reproducibility. |
aspect_ratio | string | no | — | Aspect ratio (e.g. "16:9", "1:1"). |
duration | integer | no | — | Video duration in seconds. |
multi_prompt, input_image, generate_audio, response_format, etc.).
Response
Validation
The API validates at enqueue time that:- The model exists and has image or video output capability
num_generationsis 1-4- The user is authenticated with sufficient credits
/ai/images/generate or /ai/videos/generate instead.
List Generations: GET /api/ai/queue
Lists all in-progress generations. Only actively-processing generations are returned; completed, failed, or cancelled generations are not retained.Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
namespace | string | no | Namespace to query. Defaults to the authenticated user. |
model | string | no | Filter by model name. |
Response (jobs in progress)
| Field | Always Present | Description |
|---|---|---|
count | yes | Number of in-progress generations |
generation_id | yes | Unique ID for this generation |
model | yes | Model name |
prompt | yes | Text prompt |
media_type | yes | "image" or "video" |
enqueued_at | yes | Unix timestamp when the job was enqueued |
seed | if submitted | Random seed |
aspect_ratio | if submitted | Aspect ratio |
duration | if submitted | Video duration |
Response (all jobs complete)
How Completion Works
When a generation finishes, it is removed from the queue. There is no “completed” status on this endpoint. Generations are either in the list (still processing) or gone (done). Poll untilcount reaches 0.
Polling Strategy
- Image generation (FLUX, etc.): typically completes in 5-30 seconds. Poll every 2-5 seconds.
- Video generation (Kling, etc.): typically takes 1-5 minutes. Poll every 10-30 seconds.
- Generations expire after 24 hours regardless of completion.
Get Generation: GET /api/ai/queue/:generation_id
Retrieves metadata for a single in-progress generation.Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
generation_id | string (UUID) | yes | The generation ID returned by the enqueue endpoint. |
Response (in progress)
Response (completed or not found)
Returns 404 when the generation has reached a terminal state (completed, failed, cancelled, or expired after 24h):Cancel Generation: DELETE /api/ai/queue/:generation_id
Cancels a queued or in-progress generation.Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
generation_id | string (UUID) | yes | The generation ID to cancel. |
Response (success)
Response (already completed or not found)
Returns 404:Examples
Batch image generation with polling
Async video generation
Poll a single generation by ID
Errors
| Condition | Error |
|---|---|
num_generations out of range | "num_generations must be an integer between 1 and 4" |
| Model not found | "Model not found: <name>" |
| Text-only model | ":unsupported_media_type" |
| 404 on GET/DELETE | Generation completed, cancelled, expired, or doesn’t exist |