> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oxen.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Async Queue

> Enqueue image and video generations that run in the background

## Overview

Video generation can take minutes. The async queue returns immediately with a generation ID so you can avoid long-lived HTTP connections, run generations in parallel, and build progress-tracking UIs. You can either poll the queue or use SSE to receive events when generations complete.

## Enqueue a Job

<CodeGroup>
  ```python Python theme={null}
  import requests

  API_KEY = "YOUR_API_KEY"
  HEADERS = {
      "Authorization": f"Bearer {API_KEY}",
      "Content-Type": "application/json",
  }

  response = requests.post(
      "https://hub.oxen.ai/api/ai/queue",
      headers=HEADERS,
      json={
          "model": "kling-video-v2-6-pro-text-to-video",
          "prompt": "A sunset timelapse over the ocean",
          "duration": 5,
      },
  )

  generations = response.json()["generations"]
  print(f"Enqueued {len(generations)} generation(s)")
  for g in generations:
      print(g["generation_id"], g["status"])
  ```

  ```bash cURL theme={null}
  curl -X POST https://hub.oxen.ai/api/ai/queue \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "kling-video-v2-6-pro-text-to-video",
      "prompt": "A sunset timelapse over the ocean",
      "duration": 5
    }'
  ```
</CodeGroup>

## Poll Until Done

Poll a generation by ID until its `status` reaches a terminal value (`succeeded`, `failed`, or `cancelled`). The response includes `result_url` on success and `error_message` on failure.

<CodeGroup>
  ```python Python theme={null}
  import time

  generation_id = generations[0]["generation_id"]

  while True:
      data = requests.get(
          f"https://hub.oxen.ai/api/ai/queue/{generation_id}",
          headers=HEADERS,
      ).json()
      print(f"Status: {data['status']}")
      if data["status"] in {"succeeded", "failed", "cancelled"}:
          break
      time.sleep(10)

  if data["status"] == "succeeded":
      print(f"Done! Result: {data['result_url']}")
  else:
      print(f"Generation {data['status']}: {data.get('error_message')}")
  ```

  ```bash cURL theme={null}
  curl -H "Authorization: Bearer YOUR_API_KEY" \
    "https://hub.oxen.ai/api/ai/queue/GENERATION_ID"
  ```
</CodeGroup>

You can also list all active generations with `GET /ai/queue` to see how many are still in progress:

```bash theme={null}
curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://hub.oxen.ai/api/ai/queue?model=kling-video-v2-6-pro-text-to-video"
```

## Fetch a Single Job

Use the generation ID to get a specific job's full status, including `result_url` on success:

```bash theme={null}
curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://hub.oxen.ai/api/ai/queue/GENERATION_ID"
```

## What's Next

* [Async Queue Reference](/inference-api/reference/async_queue) for the full parameter list, polling details, and cancellation
* [Video Generation Quick Start](/inference-api/quickstart/video-generation) for the synchronous counterpart
* [Model API References](/inference-api/reference/model-references) for per-model parameters you can pass through the queue
