Model Capabilities
Referencing Files as Input
Anywhere an Imagine endpoint accepts a public URL or base64-encoded image/video, you can substitute a file_id from your Files API storage. The file is fetched server-side from your private storage, so:
No bandwidth uploading the same image twice — useful for iterative editing loops.
The original file stays private (no need to make it public to use it as an input).
Works with both uploaded files and assets generated by earlier Imagine calls (via
storage_options).
The referenced file must be the correct content type for the endpoint (images: PNG/JPEG/WebP; videos: MP4) and must be fully uploaded.
Editing a stored image
import os
import xai_sdk
client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))
response = client.image.sample(
prompt="Add a party hat to the dog",
model="grok-imagine-image-quality",
image_file_id="file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a", # instead of image_url
)
print(response.url)Editing with multiple stored images
response = client.image.sample(
prompt="Blend these two scenes into one cohesive composition",
model="grok-imagine-image-quality",
image_file_ids=[
"file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a",
"file_2cd998e7-bf12-44aa-92c8-e3d1f1c1234f",
],
)Image-to-video from a stored first frame
response = client.video.generate(
prompt="Pan across the scene as the sky darkens",
model="grok-imagine-video-1.5",
duration=5,
image_file_id="file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a",
)
print(response.url)Editing a stored video
response = client.video.generate(
prompt="Add rain and a moody atmosphere",
model="grok-imagine-video",
video_file_id="file_5be118c3-da55-31dd-76e7-a1b8c8d6355b",
)Reference-to-video with multiple stored images
response = client.video.generate(
prompt="A woman in this dress walks down a city street at night",
model="grok-imagine-video-1.5",
duration=5,
reference_image_file_ids=[
"file_5be118c3-da55-31dd-76e7-a1b8c8d6355b", # subject
"file_2cd998e7-bf12-44aa-92c8-e3d1f1c1234f", # outfit
],
)Related
Files API Integration — Overview + capstone example showing inputs and outputs together.
Persisting Generated Output — The output side:
storage_options, public URLs, expiry semantics.Managing Files — Upload, list, retrieve, update, and delete files.
Last updated:July 30, 2026