Model Capabilities
Reference-to-Video
Provide reference images, a preset voice, or both to guide the generated video. Images incorporate specific people, objects, clothing, or other visual elements without locking the first frame (unlike image-to-video). This is useful for virtual try-on, product placement, character-consistent storytelling, and voice identity. On grok-imagine-video-1.5, you can also pick the voice your subject speaks in (see Reference audio), pin the exact first or last frame (see First & Last frame), and pin frames at chosen moments inside the clip (see Keyframes).
Each reference image can be provided as a public HTTPS URL, a base64-encoded data URI, or a file_id from the Files API — and you can mix kinds within a single request. See Imagine → Files API Integration for file_id details and examples.
In the Vercel AI SDK, set providerOptions.xai.mode to "reference-to-video" and pass the images with providerOptions.xai.referenceImageUrls.
import os
import xai_sdk
client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))
response = client.video.generate(
prompt="slow zoom in on the white fashion runway stage. then, the model from <IMAGE_1> walks in from the back of the shot from the white opening, and gracefully walk out onto the front of the white stage platform. they wear the shirt from <IMAGE_2> and black flared jeans. they look dramatically at the camera. high quality slow motion shot. fun, playful. skin pores. highly detailed faces. perfect shot. they reach the end of the runway and look at the camera as the camera slowly zooms. subtle smile.",
model="grok-imagine-video-1.5",
reference_image_urls=[
"<IMAGE_URL_1>",
"<IMAGE_URL_2>",
"<IMAGE_URL_3>",
],
duration=10,
aspect_ratio="16:9",
resolution="720p",
)
print(response.url)Reference audio
On grok-imagine-video-1.5, give your subject a voice by passing up to 3 preset voices with reference_audios. Each entry names a voice by voice_id, drawn from the same built-in roster as Text to Speech, so {"voice_id": "eve"} speaks in Eve's voice. Identifiers are case-insensitive; an unknown one returns 400 with the list of available voices. You can hear every voice in the flagship voices announcement.
reference_audios accepts preset voices; voice references with your own audio files are available to trusted partners on request. Use a voice alongside reference images or on its own, and tag voices in the prompt as <AUDIO_0>, <AUDIO_1>, and <AUDIO_2> (with <IMAGE_0>… when you also pass images).
import os
import xai_sdk
client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))
response = client.video.generate(
prompt="The person from <IMAGE_1> presents the product from <IMAGE_2> on the set from <IMAGE_3>, speaking with the voice from <AUDIO_0>. A second speaker with the voice from <AUDIO_1> replies.",
model="grok-imagine-video-1.5",
reference_image_urls=[
"<IMAGE_URL_1>",
"<IMAGE_URL_2>",
"<IMAGE_URL_3>",
],
reference_audios=[
{"voice_id": "eve"},
{"voice_id": "leo"},
],
duration=8,
aspect_ratio="9:16",
resolution="720p",
)
print(response.url)First & Last frame
On grok-imagine-video-1.5, last_frame pins the exact last frame of the clip. The video ends arriving on that image rather than re-rendering it as a reference. image combined with reference_images, reference_audios, or last_frame is the matching first-frame pin.
| Request shape | Result |
|---|---|
image + last_frame | Pinned first and last frame. The model interpolates between the two. |
last_frame only | Pinned last frame. The model generates the opening and lands on the pinned image. |
last_frame + reference_images / reference_audios | Pinned last frame with reference guidance. Add image to pin the first frame as well. |
prompt is optional in every first & last frame request. Include one to steer motion and camera work between the frames; omit it to let the frames alone drive the clip.
last_frame uses the same URL, data-URI, and file_id shapes as image-to-video. The Python SDK and Vercel AI SDK do not yet expose a dedicated last_frame parameter; send it on the REST body.
Classic grok-imagine-video rejects last_frame and rejects combining image with reference inputs.
import os
import time
import requests
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {os.environ['XAI_API_KEY']}",
}
response = requests.post(
"https://api.x.ai/v1/videos/generations",
headers=headers,
json={
"model": "grok-imagine-video-1.5",
"prompt": "The camera dollies from the sunlit doorway to the window, settling on the closing frame.",
"image": {"url": "<FIRST_FRAME_URL>"},
"last_frame": {"url": "<LAST_FRAME_URL>"},
"duration": 8,
"aspect_ratio": "16:9",
"resolution": "720p",
},
)
request_id = response.json()["request_id"]
while True:
result = requests.get(
f"https://api.x.ai/v1/videos/{request_id}",
headers={"Authorization": headers["Authorization"]},
)
data = result.json()
if data["status"] == "done":
print(data["video"]["url"])
break
elif data["status"] == "expired":
print("Request expired")
break
time.sleep(5)Keyframes
On grok-imagine-video-1.5, keyframes pins images at chosen moments inside the clip. Each entry pairs an image with a timestamp_s, and the video passes through that exact image at that time. Use it to storyboard a shot: the model generates the motion between your anchors rather than inventing the whole clip from one frame.
"keyframes": [
{"image": {"url": "<KEYFRAME_URL_1>"}, "timestamp_s": 2.0},
{"image": {"url": "<KEYFRAME_URL_2>"}, "timestamp_s": 4.0}
]Keyframes cover the interior of the clip; the endpoints keep their own fields. Pin the opening with image and the closing with last_frame, and combine any of the three with reference_images or reference_audios. prompt is optional whenever a frame is pinned.
| Constraint | Detail |
|---|---|
| Count | At most 4 keyframes per request. |
| Timing | timestamp_s must fall strictly inside the clip: greater than 0 and less than duration. Use image / last_frame for the endpoints. |
| Spacing | Anchors snap to a 1/3-second grid. Two keyframes that round to the same slot are rejected, so keep them at least 1/3 s apart. |
| Inputs | Each image accepts the same URL, data-URI, and file_id shapes as image-to-video. |
The Python SDK and Vercel AI SDK do not yet expose a dedicated keyframes parameter; send it on the REST body. Classic grok-imagine-video rejects keyframes, and keyframes cannot be combined with video editing.
import os
import time
import requests
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {os.environ['XAI_API_KEY']}",
}
response = requests.post(
"https://api.x.ai/v1/videos/generations",
headers=headers,
json={
"model": "grok-imagine-video-1.5",
"prompt": "A slow tracking shot through the workshop: the sketch on the bench becomes a clay model, then the finished bronze in the window.",
"image": {"url": "<FIRST_FRAME_URL>"},
"keyframes": [
{"image": {"url": "<KEYFRAME_URL_1>"}, "timestamp_s": 3.0},
{"image": {"url": "<KEYFRAME_URL_2>"}, "timestamp_s": 6.0},
],
"last_frame": {"url": "<LAST_FRAME_URL>"},
"duration": 8,
"aspect_ratio": "16:9",
"resolution": "720p",
},
)
request_id = response.json()["request_id"]
while True:
result = requests.get(
f"https://api.x.ai/v1/videos/{request_id}",
headers={"Authorization": headers["Authorization"]},
)
data = result.json()
if data["status"] == "done":
print(data["video"]["url"])
break
elif data["status"] == "expired":
print("Request expired")
break
time.sleep(5)Related
Video Generation — Generate videos from text prompts
Image-to-Video — Animate a still image
Video Editing — Edit existing videos
API Reference — Full endpoint documentation
Imagine API Landing Page — Showcase of the Imagine API in action
Last updated:September 21, 2026