Model Capabilities
Imagine Overview
The Imagine API lets you generate and edit images and videos with Grok Imagine models. Use it for image generation, image editing with up to 5 reference images, video generation from text or still images, video editing, and more.
Image Generation
Generate images from text, or edit them with up to 5 reference images.
Video Generation
Native 1080p from text or an image, lip-synced speech, up to 14 reference images and 3 voice references, and pinned frames.
Video 1.5 Lite
Text or image to video with generated audio, up to 1080p and 15 seconds, at the lowest price per second.
Pricing
Image generation uses flat per-image pricing regardless of prompt length. Each generated image incurs a fixed fee. Image edits are billed for both the input image and the generated output image. Video generation uses per-second pricing where both duration and resolution affect the total cost. For full pricing details, see the pricing page.
Image Generation
Generate new images from text prompts with Grok Imagine models. Configure output count (up to 10 images per request), aspect ratio, resolution, and response format.
import xai_sdk
client = xai_sdk.Client()
response = client.image.sample(
prompt="A collage of London landmarks in a stenciled street‑art style",
model="grok-imagine-image-2.0",
)
print(response.url)
Image Editing
Edit a source image with natural language. Provide a public image URL or base64-encoded data URI, then describe the change you want Grok Imagine to apply. Multi-image editing supports up to 5 source images in a single request for combining subjects, transferring styles, and composing scenes.
import base64
import xai_sdk
client = xai_sdk.Client()
# Load image from file and encode as base64
with open("photo.png", "rb") as f:
image_data = base64.b64encode(f.read()).decode("utf-8")
response = client.image.sample(
prompt="Render this as a pencil sketch with detailed shading",
model="grok-imagine-image-2.0",
image_url=f"data:image/png;base64,{image_data}",
)
print(response.url)
Video Generation
Animate a still image with a text prompt. The source image becomes the starting point for the generated video. Video requests are asynchronous: start a request, poll with the returned request ID, and use the completed video URL when ready. The xAI SDK and AI SDK handle polling for you.
import os
import xai_sdk
client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))
response = client.video.generate(
prompt="Make the water crash down and slowly pan out the camera",
model="grok-imagine-video-1.5",
image_url="https://docs.x.ai/assets/api-examples/video/waterfall-still.png",
duration=12,
)
print(response.url)
More Capabilities
Beyond the top use cases above, the Imagine API supports several additional workflows. The Video Overview compares the video models and shows each mode with real inputs and outputs.
- Multi-Image Editing — Combine up to 5 source images in a single edit for compositing subjects, transferring styles, and building scenes from multiple references.
- Video Generation — Generate videos from text prompts with configurable duration (up to 15s), aspect ratio, and resolution.
- Video Editing — Modify an existing video with a text prompt on
grok-imagine-video. - Reference-to-Video — Guide a video with up to 14 reference images and 3 voice references on
grok-imagine-video-1.5, and pin first, last, and mid-video frames. - Video Extension — Continue an existing video from its last frame, combining the original and extension into one clip.
- Files API Integration — Reference stored files as Imagine inputs by ID, persist generated assets to the Files API, and optionally create a permanent shareable public URL — all in a single request.
Enterprise Compliance & Security
The Imagine APIs are built for production workloads with strict security and compliance requirements. Generated media is subject to content policy review and is not used for training.
SOC 2 Type II
Audited controls for security, availability, and confidentiality
HIPAA Eligible
BAA available for healthcare applications handling PHI
GDPR Compliant
Data processing agreements and EU data residency options
Data Residency
Regional processing for compliance requirements
High Availability
Multi-region infrastructure with custom SLAs for enterprise workloads
SSO & RBAC
SAML SSO, role-based access, and audit logging
Last updated: October 5, 2026