gRPC API
Video
xai_api.Video
An API service for interaction with video generation models.
Methods of xai_api.Video
GenerateVideo
unary
Create a video based on a text prompt and optionally an image. This is an asynchronous operation. Returns immediately with a request_id for polling.
ExtendVideo
unary
Extend an existing video by generating continuation content. This is an asynchronous operation. Returns immediately with a request_id for polling.
GetDeferredVideo
unary
Gets the result of a video generation started by calling GenerateVideo or ExtendVideo.
Video generation is asynchronous. The SDK's generate() and extend() methods handle polling automatically. For manual control, use start() / extend_start() and get().
Generate a video
import os
import xai_sdk
client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))
# generate() handles polling automatically and returns the completed video
response = client.video.generate(
prompt="A serene lake at sunrise with mist rolling over the water",
model="grok-imagine-video-1.5",
duration=5,
aspect_ratio="16:9",
resolution="720p",
)
print(response.url)
Edit a video
import os
import xai_sdk
client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))
response = client.video.generate(
prompt="Give the woman a silver necklace",
model="grok-imagine-video-1.5",
video_url="https://data.x.ai/docs/video-generation/portrait-wave.mp4",
)
print(response.url)
Extend a video
import os
import xai_sdk
client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))
response = client.video.extend(
prompt="The camera slowly zooms out to reveal the city skyline",
model="grok-imagine-video-1.5",
video_url="https://data.x.ai/docs/video-generation/portrait-wave.mp4",
duration=6,
)
print(response.url)
Get video generation results
import os
import time
import xai_sdk
from xai_sdk.proto import deferred_pb2
client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))
# Manual polling (alternative to generate() which does this automatically)
start = client.video.start(
prompt="A cat lounging in a sunbeam",
model="grok-imagine-video-1.5",
)
while True:
result = client.video.get(start.request_id)
if result.status == deferred_pb2.DeferredStatus.DONE:
print(result.response.video.url)
break
elif result.status == deferred_pb2.DeferredStatus.FAILED:
print("Generation failed")
break
time.sleep(5)
Last updated: September 2, 2026