Skip to main content

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

A Server-Sent Events stream at GET /api/events can also deliver completion notifications with the output file URL. See Completion Events.

Enqueue

Submit an async image or video generation job.

Required Parameters

Additional Parameters

All other parameters (e.g. prompt, multi_prompt, input_image, input_video, aspect_ratio, duration, seed, generate_audio, response_format) are passed through to the model. Consult the model’s request_schema via GET /api/ai/models/:id for supported parameters and their constraints.

Response

Validation

The API validates at enqueue time that:
  • The model exists and has image or video output capability
  • num_generations is 1-4
  • The user is authenticated with sufficient credits
Model-specific parameter validation (prompt content, duration ranges, aspect ratio values) happens when the generation runs, not at enqueue time. If a parameter is invalid, the generation fails silently (it disappears from the queue without producing a result). To validate parameters and get immediate error feedback, use /ai/images/generate or /ai/videos/generate instead.

List Generations

Lists all in-progress generations. Only actively-processing generations are returned; completed, failed, or cancelled generations are not retained.

Query Parameters

Response (jobs in progress)

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 until count reaches 0. The output file URL is not returned by this endpoint. See Completion Events for receiving URLs via SSE.

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

Retrieves metadata for a single in-progress generation.

Path Parameters

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

Cancels a queued or in-progress generation.

Path Parameters

Response (success)

Response (already completed or not found)

Returns 404:
You can only cancel generations that are still processing. Once a generation completes and leaves the queue, the DELETE endpoint returns 404.

Completion Events

Server-Sent Events stream that emits media_generation_completed events when generations reach a terminal state.

Connect

Response is Content-Type: text/event-stream. The server sends : keep-alive\n\n every 15 seconds when idle. Events are broadcast to currently-connected subscribers with no buffering. Anything that fires before you connect is lost. Subscribe before calling POST /ai/queue to avoid missing events.

Event: media_generation_completed

Fires once per generation on terminal state. Success wire format:
Failure:

Fields

Other events on this stream

GET /api/events is a user-scoped stream that may carry unrelated event types (e.g. deployment events). Filter on the event: line and ignore anything other than media_generation_completed.

Example

Terminal states without events

media_generation_completed does not fire for:
  • Cancelled generations (you called DELETE /ai/queue/:id)
  • Expired generations (24h TTL with no worker pickup)

Examples

Batch image generation with polling

Async video generation

Poll a single generation by ID

End-to-end: enqueue, wait for SSE, download

Python

Errors