Repository Public
1<!-- source: https://docs.x.ai/developers/model-capabilities/imagine/files (from https://docs.x.ai/llms-full.txt, retrieved 2026-09-19T05:28:55Z) -->2#### Model Capabilities34# Files API Integration56The Imagine API integrates with the [Files API](/developers/files) in two directions:78* **Inputs** — anywhere an Imagine endpoint accepts a public URL or base64-encoded image/video, you can substitute a `file_id` from your Files storage. No need to make the file public or re-upload bytes on every call.9* **Outputs** — Imagine can persist the generated asset to your Files storage and optionally create a permanent, shareable public URL for it, alongside the ephemeral generation URL that's always returned by default.1011By default, Imagine requests return an **ephemeral** URL on `imgen.x.ai` or `vidgen.x.ai` that's only good for fetching the asset shortly after generation. The Files integration lets you both reuse stored inputs and persist outputs in the same request.1213> [!TIP]14>15> Need to make an already uploaded file public, or want fine-grained control over create/revoke flows? See the standalone [Files → Public URLs](/developers/files/public-urls) docs.1617## Putting it together: an iterative loop1819The clearest payoff for using inputs and outputs together is chaining Imagine calls without ever leaving the Files API. Reference a stored `file_id` directly from a previous call's `file_output` — no need to download, re-upload, or make the file public.2021```python customLanguage="pythonXAI"22import os23import xai_sdk2425client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))2627# 1. Generate an image and store it28gen = client.image.sample(29 prompt="A futuristic city skyline at night",30 model="grok-imagine-image-quality",31 storage_options={"filename": "city.jpg"}, # store privately, no public URL needed32)33city = gen.file_output.file_id3435# 2. Edit the stored image without re-uploading36edit = client.image.sample(37 prompt="Add neon signs to the buildings",38 model="grok-imagine-image-quality",39 image_file_id=city,40 storage_options={"filename": "city-neon.jpg"},41)4243# 3. Animate the edited result into a video44vid = client.video.generate(45 prompt="A camera pulls back through the city",46 model="grok-imagine-video-1.5",47 duration=5,48 image_file_id=edit.file_output.file_id,49)5051print(vid.url)52```5354## Related5556* [Referencing Files as Input](/developers/model-capabilities/imagine/files/inputs) — Full reference + examples for the input direction.57* [Persisting Generated Output](/developers/model-capabilities/imagine/files/outputs) — Full reference + examples for the output direction.58* [Files → Public URLs](/developers/files/public-urls) — Public URL lifecycle for any file, regardless of how it was created.59* [Managing Files](/developers/files/managing-files) — Upload, list, retrieve, update, and delete files.60