2 2
3# Video Generation3# Video Generation
4 4
5Generate videos from text prompts with Grok video models. The API supports configurable duration, aspect ratio, and resolution, and the SDK handles asynchronous polling automatically.5Generate videos from text prompts with Grok video models. The API supports configurable duration, aspect ratio, and resolution, and the SDK handles asynchronous polling automatically. On `grok-imagine-video-1.5`, text-to-video supports native 1080p.
6 6
7## Quick Start7## Quick Start
8 8
16 16
17response = client.video.generate(17response = client.video.generate(
18 prompt="A glowing crystal-powered rocket launching from the red dunes of Mars, ancient alien ruins lighting up in the background as it soars into a sky full of unfamiliar constellations",18 prompt="A glowing crystal-powered rocket launching from the red dunes of Mars, ancient alien ruins lighting up in the background as it soars into a sky full of unfamiliar constellations",
19 model="grok-imagine-video",19 model="grok-imagine-video-1.5",
20 duration=10,20 duration=10,
21 aspect_ratio="16:9",21 aspect_ratio="16:9",
22 resolution="720p",22 resolution="720p",
39 "https://api.x.ai/v1/videos/generations",39 "https://api.x.ai/v1/videos/generations",
40 headers=headers,40 headers=headers,
41 json={41 json={
42 "model": "grok-imagine-video",42 "model": "grok-imagine-video-1.5",
43 "prompt": "A glowing crystal-powered rocket launching from the red dunes of Mars, ancient alien ruins lighting up in the background as it soars into a sky full of unfamiliar constellations",43 "prompt": "A glowing crystal-powered rocket launching from the red dunes of Mars, ancient alien ruins lighting up in the background as it soars into a sky full of unfamiliar constellations",
44 "duration": 10,44 "duration": 10,
45 "aspect_ratio": "16:9",45 "aspect_ratio": "16:9",
70import { experimental_generateVideo as generateVideo } from "ai";70import { experimental_generateVideo as generateVideo } from "ai";
71 71
72const result = await generateVideo({72const result = await generateVideo({
73 model: xai.video("grok-imagine-video"),73 model: xai.video("grok-imagine-video-1.5"),
74 prompt: "A glowing crystal-powered rocket launching from the red dunes of Mars, ancient alien ruins lighting up in the background as it soars into a sky full of unfamiliar constellations",74 prompt: "A glowing crystal-powered rocket launching from the red dunes of Mars, ancient alien ruins lighting up in the background as it soars into a sky full of unfamiliar constellations",
75 duration: 10,75 duration: 10,
76 aspectRatio: "16:9",76 aspectRatio: "16:9",
89 -H "Content-Type: application/json" \89 -H "Content-Type: application/json" \
90 -H "Authorization: Bearer $XAI_API_KEY" \90 -H "Authorization: Bearer $XAI_API_KEY" \
91 -d '{91 -d '{
92 "model": "grok-imagine-video",92 "model": "grok-imagine-video-1.5",
93 "prompt": "A glowing crystal-powered rocket launching from the red dunes of Mars, ancient alien ruins lighting up in the background as it soars into a sky full of unfamiliar constellations",93 "prompt": "A glowing crystal-powered rocket launching from the red dunes of Mars, ancient alien ruins lighting up in the background as it soars into a sky full of unfamiliar constellations",
94 "duration": 10,94 "duration": 10,
95 "aspect_ratio": "16:9",95 "aspect_ratio": "16:9",
116 116
117* **Prompt complexity** — More detailed scenes require additional processing117* **Prompt complexity** — More detailed scenes require additional processing
118* **Duration** — Longer videos take more time to generate118* **Duration** — Longer videos take more time to generate
119* **Resolution** — Higher resolutions (720p vs 480p) increase processing time119* **Resolution** — Higher resolutions (1080p vs 480p) increase processing time
120* **Video editing** — Editing existing videos adds overhead compared to image-to-video or text-to-video120* **Video editing** — Editing existing videos adds overhead compared to image-to-video or text-to-video
121 121
122## Video workflows122## Video workflows
123 123
124Use the page that matches the kind of video output you want to create:124Use the page that matches the kind of video output you want to create:
125 125
126* [Video Generation](/developers/model-capabilities/video/generation) — Generate videos from text prompts.
127* [Image-to-Video](/developers/model-capabilities/video/image-to-video) — Animate a still image.126* [Image-to-Video](/developers/model-capabilities/video/image-to-video) — Animate a still image.
128* [Video Editing](/developers/model-capabilities/video/editing) — Modify an existing video.127* [Video Editing](/developers/model-capabilities/video/editing) — Modify an existing video.
129* [Reference-to-Video](/developers/model-capabilities/video/reference-to-video) — Guide a generated video with one or more reference images.128* [Reference-to-Video](/developers/model-capabilities/video/reference-to-video) — Guide a generated video with one or more reference images.
147 -H "Content-Type: application/json" \146 -H "Content-Type: application/json" \
148 -H "Authorization: Bearer $XAI_API_KEY" \147 -H "Authorization: Bearer $XAI_API_KEY" \
149 -d '{148 -d '{
150 "model": "grok-imagine-video",149 "model": "grok-imagine-video-1.5",
151 "prompt": "A glowing crystal-powered rocket launching from Mars"150 "prompt": "A glowing crystal-powered rocket launching from Mars"
152 }'151 }'
153```152```
186 "duration": 8,185 "duration": 8,
187 "respect_moderation": true186 "respect_moderation": true
188 },187 },
189 "model": "grok-imagine-video"188 "model": "grok-imagine-video-1.5"
190}189}
191```190```
192 191
194 193
195## Configuration194## Configuration
196 195
197The video generation API lets you control the output format of your generated videos. You can specify the duration, aspect ratio, and resolution to match your specific use case.196The video generation API lets you control the output format of your generated videos. You can specify the duration, aspect ratio, resolution, and (on reference-to-video) a preset voice to match your specific use case.
198 197
199### Duration198### Duration
200 199
223| `720p` | HD quality |222| `720p` | HD quality |
224| `480p` | Standard definition, faster processing (default) |223| `480p` | Standard definition, faster processing (default) |
225 224
226> **Note:** `1080p` is only supported on `grok-imagine-video-1.5` for image-to-video generation.225**Note:** `1080p` is supported on `grok-imagine-video-1.5` for text-to-video and image-to-video. Reference-to-video is capped at 720p.
227 226
228Video editing does not support custom `resolution`. The output resolution matches the input video's resolution, capped at 720p (e.g., a 1080p input will be downsized to 720p).227Video editing does not support custom `resolution`. The output resolution matches the input video's resolution, capped at 720p (e.g., a 1080p input will be downsized to 720p).
229 228
229### Audio
230
231> [!WARNING]
232>
233> Reference audio is currently only available in the **United States**, for trusted partners. .
234
235On `grok-imagine-video-1.5`, [reference-to-video](/developers/model-capabilities/video/reference-to-video#reference-audio) can carry a voice via `reference_audios`. Voices come from the built-in roster and are named by `voice_id`; you cannot upload your own audio clips:
236
237| Property | Description |
238|----------|-------------|
239| Source | A preset `voice_id` (e.g. `{"voice_id": "eve"}`), from the same roster as [Text to Speech](/developers/model-capabilities/audio/text-to-speech#voices). Identifiers are case-insensitive |
240| Limit | Max **3** voices per request |
241| Prompt | Reference voices by index: `<AUDIO_0>`, `<AUDIO_1>`, `<AUDIO_2>` |
242
243Generated videos include an audio track by default.
244
230### Example245### Example
231 246
232```python customLanguage="pythonXAI"247```python customLanguage="pythonXAI"
237 252
238response = client.video.generate(253response = client.video.generate(
239 prompt="Timelapse of a flower blooming in a sunlit garden",254 prompt="Timelapse of a flower blooming in a sunlit garden",
240 model="grok-imagine-video",255 model="grok-imagine-video-1.5",
241 duration=10,256 duration=10,
242 aspect_ratio="16:9",257 aspect_ratio="16:9",
243 resolution="720p",258 resolution="720p",
261 "https://api.x.ai/v1/videos/generations",276 "https://api.x.ai/v1/videos/generations",
262 headers=headers,277 headers=headers,
263 json={278 json={
264 "model": "grok-imagine-video",279 "model": "grok-imagine-video-1.5",
265 "prompt": "Timelapse of a flower blooming in a sunlit garden",280 "prompt": "Timelapse of a flower blooming in a sunlit garden",
266 "duration": 10,281 "duration": 10,
267 "aspect_ratio": "16:9",282 "aspect_ratio": "16:9",
292import { experimental_generateVideo as generateVideo } from "ai";307import { experimental_generateVideo as generateVideo } from "ai";
293 308
294const result = await generateVideo({309const result = await generateVideo({
295 model: xai.video("grok-imagine-video"),310 model: xai.video("grok-imagine-video-1.5"),
296 prompt: "Timelapse of a flower blooming in a sunlit garden",311 prompt: "Timelapse of a flower blooming in a sunlit garden",
297 duration: 10,312 duration: 10,
298 aspectRatio: "16:9",313 aspectRatio: "16:9",
311 -H "Content-Type: application/json" \326 -H "Content-Type: application/json" \
312 -H "Authorization: Bearer $XAI_API_KEY" \327 -H "Authorization: Bearer $XAI_API_KEY" \
313 -d '{328 -d '{
314 "model": "grok-imagine-video",329 "model": "grok-imagine-video-1.5",
315 "prompt": "Timelapse of a flower blooming in a sunlit garden",330 "prompt": "Timelapse of a flower blooming in a sunlit garden",
316 "duration": 10,331 "duration": 10,
317 "aspect_ratio": "16:9",332 "aspect_ratio": "16:9",
342|------|-----------------|--------------|-------------|357|------|-----------------|--------------|-------------|
343| Text-to-video | `prompt` only | `prompt: "..."` | Generates video from a text prompt alone. |358| Text-to-video | `prompt` only | `prompt: "..."` | Generates video from a text prompt alone. |
344| Image-to-video | `prompt` + `image` | `prompt: { image, text }` | Generates video with the provided image as the starting frame. |359| Image-to-video | `prompt` + `image` | `prompt: { image, text }` | Generates video with the provided image as the starting frame. |
345| Reference-to-video | `prompt` + `reference_images` | `prompt: "..."` + `providerOptions.xai.{ mode: "reference-to-video", referenceImageUrls }` | Generates video guided by one or more reference images. |360| Reference-to-video | `prompt` + `reference_images` or `reference_audios` | `prompt: "..."` + `providerOptions.xai.{ mode: "reference-to-video", referenceImageUrls }` | Generates video guided by reference images and/or a preset voice on `grok-imagine-video-1.5`. |
346| Edit-video | `/v1/videos/edits` + `video` | `prompt: "..."` + `providerOptions.xai.{ mode: "edit-video", videoUrl }` | Modifies an existing video based on the prompt. |361| Edit-video | `/v1/videos/edits` + `video` | `prompt: "..."` + `providerOptions.xai.{ mode: "edit-video", videoUrl }` | Modifies an existing video based on the prompt. |
347| Extend-video | `/v1/videos/extensions` + `video` | `prompt: "..."` + `providerOptions.xai.{ mode: "extend-video", videoUrl }` | Extends an existing video from its last frame. |362| Extend-video | `/v1/videos/extensions` + `video` | `prompt: "..."` + `providerOptions.xai.{ mode: "extend-video", videoUrl }` | Extends an existing video from its last frame. |
348 363
371 386
372response = client.video.generate(387response = client.video.generate(
373 prompt="Epic cinematic drone shot flying through mountain peaks",388 prompt="Epic cinematic drone shot flying through mountain peaks",
374 model="grok-imagine-video",389 model="grok-imagine-video-1.5",
375 duration=15,390 duration=15,
376 timeout=timedelta(minutes=15), # Wait up to 15 minutes391 timeout=timedelta(minutes=15), # Wait up to 15 minutes
377 interval=timedelta(seconds=5), # Check every 5 seconds392 interval=timedelta(seconds=5), # Check every 5 seconds
385import { experimental_generateVideo as generateVideo } from "ai";400import { experimental_generateVideo as generateVideo } from "ai";
386 401
387const result = await generateVideo({402const result = await generateVideo({
388 model: xai.video("grok-imagine-video"),403 model: xai.video("grok-imagine-video-1.5"),
389 prompt: "Epic cinematic drone shot flying through mountain peaks",404 prompt: "Epic cinematic drone shot flying through mountain peaks",
390 duration: 15,405 duration: 15,
391 providerOptions: {406 providerOptions: {
419# Start the generation request434# Start the generation request
420start_response = client.video.start(435start_response = client.video.start(
421 prompt="A cat lounging in a sunbeam, tail gently swishing",436 prompt="A cat lounging in a sunbeam, tail gently swishing",
422 model="grok-imagine-video",437 model="grok-imagine-video-1.5",
423 duration=5,438 duration=5,
424)439)
425 440
458 "https://api.x.ai/v1/videos/generations",473 "https://api.x.ai/v1/videos/generations",
459 headers=headers,474 headers=headers,
460 json={475 json={
461 "model": "grok-imagine-video",476 "model": "grok-imagine-video-1.5",
462 "prompt": "A cat lounging in a sunbeam, tail gently swishing",477 "prompt": "A cat lounging in a sunbeam, tail gently swishing",
463 "duration": 5,478 "duration": 5,
464 },479 },
498 "Authorization": `Bearer ${process.env.XAI_API_KEY}`,513 "Authorization": `Bearer ${process.env.XAI_API_KEY}`,
499 },514 },
500 body: JSON.stringify({515 body: JSON.stringify({
501 model: "grok-imagine-video",516 model: "grok-imagine-video-1.5",
502 prompt: "A cat lounging in a sunbeam, tail gently swishing",517 prompt: "A cat lounging in a sunbeam, tail gently swishing",
503 duration: 5,518 duration: 5,
504 }),519 }),
537 -H "Content-Type: application/json" \552 -H "Content-Type: application/json" \
538 -H "Authorization: Bearer $XAI_API_KEY" \553 -H "Authorization: Bearer $XAI_API_KEY" \
539 -d '{554 -d '{
540 "model": "grok-imagine-video",555 "model": "grok-imagine-video-1.5",
541 "prompt": "A cat lounging in a sunbeam, tail gently swishing",556 "prompt": "A cat lounging in a sunbeam, tail gently swishing",
542 "duration": 5557 "duration": 5
543 }' | jq -r '.request_id')558 }' | jq -r '.request_id')
584try:599try:
585 response = client.video.generate(600 response = client.video.generate(
586 prompt="A cat lounging in a sunbeam, tail gently swishing",601 prompt="A cat lounging in a sunbeam, tail gently swishing",
587 model="grok-imagine-video",602 model="grok-imagine-video-1.5",
588 duration=5,603 duration=5,
589 )604 )
590 print(response.url)605 print(response.url)
636try:651try:
637 response = client.video.generate(652 response = client.video.generate(
638 prompt="A cat lounging in a sunbeam, tail gently swishing",653 prompt="A cat lounging in a sunbeam, tail gently swishing",
639 model="grok-imagine-video",654 model="grok-imagine-video-1.5",
640 duration=5,655 duration=5,
641 )656 )
642 print(response.url)657 print(response.url)
662 677
663```javascript customLanguage="javascriptAISDK"678```javascript customLanguage="javascriptAISDK"
664const result = await generateVideo({679const result = await generateVideo({
665 model: xai.video("grok-imagine-video"),680 model: xai.video("grok-imagine-video-1.5"),
666 prompt: "A futuristic city skyline at dusk",681 prompt: "A futuristic city skyline at dusk",
667 duration: 5,682 duration: 5,
668});683});
691 tasks = [706 tasks = [
692 client.video.generate(707 client.video.generate(
693 prompt=prompt,708 prompt=prompt,
694 model="grok-imagine-video",709 model="grok-imagine-video-1.5",
695 duration=5,710 duration=5,
696 )711 )
697 for prompt in prompts712 for prompt in prompts