Why Use the Async Queue
The synchronous endpoints (/images/generate, /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
Request Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | yes | — | Must be an image or video model. Text-only models are rejected. |
prompt | string | no | — | Text prompt. |
num_generations | integer | no | 1 | How many generations to run in parallel. Range: 1-4. |
multi_prompt, duration, aspect_ratio, input_image, generate_audio, seed, response_format, target_namespace, 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
/images/generate or /videos/generate instead.
Poll Status: GET /api/media/generations/status/:namespace/*model_name
Check the status of queued generations for a specific model.:namespace: Your username (e.g.myuser)*model_name: The model name used to enqueue (e.g.kling-video-o3-pro-reference-to-video)
Response (jobs in progress)
| Field | Always Present | Description |
|---|---|---|
generation_id | yes | Unique ID for this generation |
model | yes | Model name |
model_name | yes | Same as model |
enqueued_at | yes | Unix timestamp when the job was enqueued |
prompt | if submitted | Your text prompt |
multi_prompt | if submitted | Your multi-shot prompts |
| other params | if submitted | Any other parameters you passed |
Response (all jobs complete)
How Completion Works
When a generation finishes, it is removed from the status list. There is no “completed” status. 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.
Cancel: DELETE /api/media/generations/:namespace/:generation_id
Cancel a queued or in-progress generation.Response (success)
Response (already completed or not found)
Returns 404:Examples
Batch image generation with polling
Async video generation
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 DELETE | Generation already completed or doesn’t exist |