Grok Imagine Video API: Text to Video in Python
Create a job, poll it, download the MP4. Here is a script that runs as is.

On this page
- Short answer
- How does the Grok Imagine Video API work?
- Which parameters can you set?
- How do you turn a text prompt into a video in Python?
- How much does a clip cost, and how long does it take?
- What errors will you hit?
- Common questions
- Is the Grok Imagine Video API free?
- How long can a Grok Imagine video be?
- Does Grok Imagine Video make sound?
- Can Grok Imagine turn an image into a video?
- What is the difference between Grok Imagine Video 1.5 and 1.5 Lite?
- Is grok-imagine-video-1.5-preview still a valid model ID?
The Grok Imagine Video API is asynchronous: you send a prompt to create a job, poll the job ID until it finishes, then download the MP4. The current model is grok-imagine-video-1.5. On October 24, 2026, our 6-second 720p clip was ready 46 seconds after we sent the request, and it had a sound track.
Below: the script that runs as is, the parameters that matter, what a clip costs and how long it takes, plus the errors you will hit.
Short answer
- Model:
grok-imagine-video-1.5. xAI says 1.5 left preview and became generally available on June 16, 2026 (xAI). - Settings:
durationfrom 4 to 15 seconds,resolution"720p"and aratiosuch as"16:9". - Cost: $0.14 per second at 720p at xAI's list price, so $0.84 for a 6-second clip (xAI models page, checked October 24, 2026).
- Time: our 6-second 720p job took 46 seconds. Poll the same task ID and download the file within an hour.

How does the Grok Imagine Video API work?
It is a three-step job: create, poll, download (xAI's video generation guide, checked October 24, 2026).
On xAI's own API you send a POST request to https://api.x.ai/v1/videos/generations with the model ID and the prompt and get a request_id back. Then you poll https://api.x.ai/v1/videos/{request_id} with GET until the job is done, and read video.url (same guide).
| Use it for | Model ID |
|---|---|
| References, voices, 1080p | grok-imagine-video-1.5 |
| Simple videos, cheapest | grok-imagine-video-1.5-lite |
| Older model | grok-imagine-video |
xAI recommends grok-imagine-video-1.5-lite for simple videos and grok-imagine-video-1.5 when you need references, voices, pinned frames or native 1080p (video overview, checked October 24, 2026). For still images, the Grok Imagine image API guide covers xAI's three image models; to compare Grok with other video APIs, read our video model roundup.
OmniaKey sells API access to Grok Imagine Video 1.5, so we ran the example through it. The calls are POST https://api.omniakey.com/v1/media/tasks with an Idempotency-Key header, which answers 202 with an id, and GET /v1/media/tasks/{id} for the status (OmniaKey media overview, checked October 24, 2026). The same create, poll, download flow works for the other video models in the video API docs: Kling 3.0, Seedance, Wan 3.0, MiniMax H3 and HappyHorse. Every price below is xAI's own.
| xAI field | OmniaKey field |
|---|---|
prompt | input.prompt |
duration | parameters.duration |
resolution | parameters.resolution |
aspect_ratio | parameters.ratio |
request_id | id |
video.url | assets[0].url |
The xAI field names come from its Videos API reference and the OmniaKey names from its video API docs, both checked October 24, 2026.
Which parameters can you set?
Three settings and the prompt decide what you get.
| Parameter | What we used | What is allowed |
|---|---|---|
| duration | 6 | 4–15 seconds |
| resolution | "720p" | Up to 720p |
| ratio | "16:9" | 9 ratios |
durationis required on OmniaKey and decides the price (OmniaKey video docs). OmniaKey's minimum for this model is 4 seconds and xAI's maximum is 15 (video generation guide), so stay between 4 and 15.resolution: send lowercase"720p". OmniaKey serves Grok video at up to 720p (OmniaKey media overview). xAI's own API adds 480p, its default, and native 1080p (generation guide).ratiotakes nine values: 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 21:9 and 5:2, with 16:9 as the default (video generation guide). We ran 16:9.nmust be 1 (OmniaKey video docs).- The prompt: describe the shot, the light, the camera move, then add a
Sound:line. Anything you name there can appear on screen: our sound line mentioned a spoon, and a spoon and a hand turned up in the picture.
How do you turn a text prompt into a video in Python?
Install requests, put the key in OMNIAKEY_API_KEY, and run the script.
pip install requests
export OMNIAKEY_API_KEY="your-key"
Here is the script we ran, unchanged:
import os
import time
import uuid
import requests
API = "https://api.omniakey.com/v1/media/tasks"
HEADERS = {"Authorization": f"Bearer {os.environ['OMNIAKEY_API_KEY']}"}
PROMPT = (
"Close-up of a white ceramic coffee cup on a wooden café table by a window, "
"morning sunlight, steam curling up from the coffee, the camera slowly pushes in, "
"shallow depth of field. Sound: quiet café chatter and a spoon clinking on a saucer."
)
# 1. Create the job. Reuse the same Idempotency-Key only when retrying this exact request.
job = requests.post(
API,
headers={**HEADERS, "Idempotency-Key": str(uuid.uuid4())},
json={
"model": "grok-imagine-video-1.5",
"type": "video",
"operation": "text_to_video",
"input": {"prompt": PROMPT},
"parameters": {"duration": 6, "resolution": "720p", "ratio": "16:9"},
},
timeout=30,
)
job.raise_for_status()
task = job.json()
print("task:", task["id"], task["status"])
# 2. Poll the job until it finishes. A slow job has not failed: keep polling the same id.
while True:
task = requests.get(f"{API}/{task['id']}", headers=HEADERS, timeout=30).json()
if task["status"] not in ("queued", "processing"):
break
time.sleep(5)
if task["status"] != "succeeded":
raise SystemExit(f"job ended {task['status']}: {task.get('error')}")
# 3. Download the clip now: the signed URL expires in about an hour.
asset = task["assets"][0]
with open("coffee.mp4", "wb") as f:
f.write(requests.get(asset["url"], timeout=120).content)
print("saved coffee.mp4", asset["mime_type"], asset["byte_size"], "bytes")
Its last line of output on October 24, 2026:
saved coffee.mp4 video/mp4 2659230 bytes
The script's first line prints the task ID and status. Keep that ID: it is how you find the job again if the script stops.
One 6-second 720p job came back like this:
| What came back | Value |
|---|---|
| Time to finish | 46 s |
| Duration | 6.04 s |
| Size | 1280×720 |
| Frame rate | 24 fps |
| Audio | Stereo AAC |
| File size | 2.7 MB |
The clip follows the prompt: a white ceramic cup of black coffee on a white saucer, on a wooden café table by a window, with steam curling up and the café blurred behind it. The camera pushes in steadily, and the cup grows from about a third of the frame width to about half. A spoon comes in from the right at 4.5 seconds. The audio is a quiet track with one sharp peak at 4.8 seconds, right as the spoon touches the saucer.
How much does a clip cost, and how long does it take?
xAI bills video per second, and the rate depends on the model and the resolution. Its models page (checked October 24, 2026) breaks the price out by resolution, and the flat $0.080 per second on its pricing page is the 480p rate.
| Model | 480p | 720p | 1080p |
|---|---|---|---|
| 1.5 | $0.08 | $0.14 | $0.25 |
| 1.5 Lite | $0.02 | $0.03 | $0.14 |
| Older model | $0.05 | $0.07 | — |
At those list prices:
- 6 seconds on 1.5 at 720p: 6 × $0.14 = $0.84.
- 8 seconds, the default length, on 1.5 at 480p: 8 × $0.08 = $0.64.
- 15 seconds on 1.5 at 1080p: 15 × $0.25 = $3.75.
- 6 seconds on 1.5 Lite at 720p: 6 × $0.03 = $0.18.
xAI publishes only per-second video rates (pricing page, checked October 24, 2026).
On OmniaKey the charge is the duration you request times the per-second rate, taken from your balance when the job is created, and refunded automatically if the job fails (OmniaKey video docs, checked October 24, 2026). Our 6-second request returned a 6.04-second file and was billed as 6 seconds. Current rates are on the Grok Imagine Video 1.5 page.
Our job took 46 seconds from request to succeeded. xAI says generation "typically takes up to several minutes", and its own SDK waits up to 10 minutes (generation guide). Poll every few seconds. If you add a deadline to the loop, make it generous, and when it passes, look the job up again by its ID instead of sending a new request.
The signed link lives about an hour, and ours expired exactly one hour after the job finished. The task record is kept for 24 hours, so you can poll again for a fresh link (OmniaKey media overview, checked October 24, 2026).
What errors will you hit?
Most errors come back right away, before a job is created, so they cost nothing. A job that fails later ends as failed and is refunded. OmniaKey's media docs (checked October 24, 2026) list these, among others:
| Error | Cause | Fix |
|---|---|---|
400 missing_idempotency_key | No Idempotency-Key header | Add one |
409 idempotency_key_reused | Same key, new body | New key per job |
400 model_price_error | Unsupported duration or resolution | 4–15 s, "720p" |
403 model_not_allowed | Key lacks this model | Check key access |
503 no_available_channel | Model unavailable right now | Retry later |
Task failed | Provider error | Read error.message |
We triggered the first two on purpose on October 24, 2026. Leaving out the header returned HTTP 400:
{"error":{"code":"missing_idempotency_key","message":"Idempotency-Key is required and must be at most 255 characters"}}
Reusing the job's key with a changed prompt returned HTTP 409:
{"error":{"code":"idempotency_key_reused","message":"Idempotency-Key was already used with a different request"}}
- Treat a slow job as still running. Keep polling the same task ID; sending the request again with a new
Idempotency-Keystarts, and bills, a second job. - A replayed request answers
200with the original task and noassetslist, which is why the script fetches the task before it readsassets.
Common questions
Is the Grok Imagine Video API free?
No. xAI publishes only per-second rates, and the cheapest is 1.5 Lite at $0.02 per second at 480p (models page, checked October 24, 2026).
How long can a Grok Imagine video be?
1 to 15 seconds on xAI's API, and 8 seconds by default (video generation guide). Through OmniaKey, use 4 to 15 seconds: OmniaKey's minimum for this model is 4 (OmniaKey video docs, checked October 24, 2026), and xAI's maximum is 15.
Does Grok Imagine Video make sound?
Yes, an audio track by default, with sound effects, ambience and dialogue generated with the picture (video generation guide; xAI announcement). Ours had a stereo AAC track. xAI's API takes generate_audio: false for a silent clip; to strip the track from a downloaded file, run:
ffmpeg -i coffee.mp4 -an -c:v copy coffee-silent.mp4
Can Grok Imagine turn an image into a video?
Yes, in xAI's API: pass the image as image (a public URL, a base64 data URI or a Files API file_id; JPEG, PNG or WebP), it becomes the first frame, the prompt is optional, and the clip keeps the image's aspect ratio (image-to-video guide; Videos API reference). We'll add an image-to-video example through OmniaKey here once we have verified it end to end.
What is the difference between Grok Imagine Video 1.5 and 1.5 Lite?
Lite is the cheapest per second, does text- and image-to-video with lip-synced speech, reaches 1080p by upscaling 720p, and has no reference images, voice references or keyframes (video overview; Lite model page). The examples here use 1.5, which you can call on OmniaKey as Grok Imagine Video 1.5.
Is grok-imagine-video-1.5-preview still a valid model ID?
xAI still lists it as an alias, but 1.5 left preview and became generally available on June 16, 2026 (model page; xAI announcement). Use grok-imagine-video-1.5.
Models in this article
Related articles
Grok Imagine API: Python Guide and 3 Models Tested Side by Side
Three Grok image models, the same four prompts. Here is which to use.
Best AI video API models in 2026
There is no single best video model. The right route depends on whether you need a long shot, a faithful first frame, reference images, predictable cost, or a faster production queue.
Kling 3.0 vs Seedance 2.5
Both models are live on OmniaKey and both can serve the same brief. One is billed once per generation from a mode and duration matrix, the other per output second by resolution — and only one of them accepts a reference-driven shot.