Skip to main content

Video Generation

Level: Intermediate · Category: API reference

Tags: Text-to-video · Image-to-video · Jobs

wan-2-2 (Wan2.2 TI2V-5B) makes short video clips from a text prompt, or from a prompt and a first frame. A clip takes minutes, so the API is a job: you create it, poll it, then download the MP4. It follows the OpenAI Videos API shape. Keys and setup are on LLM API Access.

Method and pathWhat it does
POST /v1/videosCreate a job. Returns its id and status: "queued".
GET /v1/videos/{id}The job's status (queued, in_progress, completed, failed) and progress (0 to 100)
GET /v1/videos/{id}/contentThe finished MP4. Returns 409 while the clip is still rendering.
DELETE /v1/videos/{id}Delete the job and its file
GET /v1/videosYour jobs, newest first

Jobs are private to the API key that created them: another key, even your own, gets 404 for the same id. Finished jobs are kept for 24 hours, so download the MP4 soon after it completes.

Make a clip​

import os
import time

import requests

API = "https://openai.rc.asu.edu/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['OPENAI_API_KEY']}"}

job = requests.post(f"{API}/videos", headers=HEADERS, json={
"model": "wan-2-2",
"prompt": "a saguaro cactus at sunrise, slow camera pan",
"size": "1280x704",
"seconds": 2,
"steps": 10,
}).json()

while job["status"] not in ("completed", "failed"):
time.sleep(15)
job = requests.get(f"{API}/videos/{job['id']}", headers=HEADERS).json()
print(job["status"], job.get("progress"))

if job["status"] == "completed":
video = requests.get(f"{API}/videos/{job['id']}/content", headers=HEADERS)
with open("clip.mp4", "wb") as f:
f.write(video.content)

In testing, this 2-second clip at 10 steps finished in about 45 seconds.

Options​

FieldMeaning
promptWhat happens in the clip
sizeWIDTHxHEIGHT; both multiples of 32. The model's native size is 1280x704.
secondsClip length. Clips are 24 frames per second, and the frame count is rounded to the nearest one the model accepts, so a clip can be a few hundredths of a second off (the job reports the real length as a string, for example "2.04"). The model was trained on 5-second clips.
stepsDenoising steps: fewer is faster, more is sharper. A 5-second clip at 20 steps takes about 3 minutes once the model is warm.
input_referenceA first frame (image to video). Send the request as multipart/form-data with the image as a file.

Image to video with curl:

curl -s https://openai.rc.asu.edu/v1/videos \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-F model=wan-2-2 \
-F prompt="the camera pushes slowly forward" \
-F input_reference=@first_frame.png \
-F seconds=5

Each server renders one clip at a time, and when every server is busy, new jobs wait in the queue.