Skip to main content

Overview

Video generation can take minutes. The async queue returns immediately with a generation id so you can avoid long-lived HTTP connections, run up to 4 generations in parallel, and build progress-tracking UIs.

Enqueue a Job

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"])

Poll Until Done

List in-progress generations with GET /ai/queue. A generation drops off the list once it finishes (or fails).
import time

MODEL = "kling-video-v2-6-pro-text-to-video"

while True:
    status = requests.get(
        "https://hub.oxen.ai/api/ai/queue",
        headers=HEADERS,
        params={"model": MODEL},
    ).json()
    if status["count"] == 0:
        break
    print(f"Still processing: {status['count']} remaining")
    time.sleep(10)

print("Done!")

Fetch a Single Job

Use the generation id when you want one job’s status without listing everything:
curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://hub.oxen.ai/api/ai/queue/GENERATION_ID"

What’s Next