SPB Git

Repository Public

inputs.md 5.0 KB 153 lines markdown

1<!-- source: https://docs.x.ai/developers/model-capabilities/imagine/files/inputs (from https://docs.x.ai/llms-full.txt, retrieved 2026-09-19T05:28:55Z) -->2#### Model Capabilities34# Referencing Files as Input56Anywhere an Imagine endpoint accepts a public URL or base64-encoded image/video, you can substitute a `file_id` from your [Files API](/developers/files) storage. The file is fetched server-side from your private storage, so:78* No bandwidth uploading the same image twice — useful for iterative editing loops.9* The original file stays private (no need to make it public to use it as an input).10* Works with both uploaded files and assets generated by earlier Imagine calls (via [`storage_options`](/developers/model-capabilities/imagine/files/outputs)).1112The referenced file must be the correct content type for the endpoint (images: PNG/JPEG/WebP; videos: MP4) and must be fully uploaded.1314## Editing a stored image1516```python customLanguage="pythonXAI"17import os18import xai_sdk1920client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))2122response = client.image.sample(23    prompt="Add a party hat to the dog",24    model="grok-imagine-image-quality",25    image_file_id="file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a",  # instead of image_url26)2728print(response.url)29```3031```bash32curl -s -X POST https://api.x.ai/v1/images/edits \33  -H "Authorization: Bearer $XAI_API_KEY" \34  -H "Content-Type: application/json" \35  -d '{36    "model": "grok-imagine-image-quality",37    "prompt": "Add a party hat to the dog",38    "image": { "file_id": "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a" },39    "response_format": "url"40  }'41```4243## Editing with multiple stored images4445```python customLanguage="pythonXAI"46response = client.image.sample(47    prompt="Blend these two scenes into one cohesive composition",48    model="grok-imagine-image-quality",49    image_file_ids=[50        "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a",51        "file_2cd998e7-bf12-44aa-92c8-e3d1f1c1234f",52    ],53)54```5556```bash57# Each images entry independently carries url or file_id — mix kinds within a single request.58curl -s -X POST https://api.x.ai/v1/images/edits \59  -H "Authorization: Bearer $XAI_API_KEY" \60  -H "Content-Type: application/json" \61  -d '{62    "model": "grok-imagine-image-quality",63    "prompt": "Blend these two scenes into one cohesive composition",64    "images": [65      { "file_id": "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a" },66      { "url": "https://example.com/scene-b.jpg" }67    ],68    "response_format": "url"69  }'70```7172## Image-to-video from a stored first frame7374```python customLanguage="pythonXAI"75response = client.video.generate(76    prompt="Pan across the scene as the sky darkens",77    model="grok-imagine-video-1.5",78    duration=5,79    image_file_id="file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a",80)8182print(response.url)83```8485```bash86curl -s -X POST https://api.x.ai/v1/videos/generations \87  -H "Authorization: Bearer $XAI_API_KEY" \88  -H "Content-Type: application/json" \89  -d '{90    "model": "grok-imagine-video-1.5",91    "prompt": "Pan across the scene as the sky darkens",92    "duration": 5,93    "image": { "file_id": "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a" }94  }'95```9697## Editing a stored video9899```python customLanguage="pythonXAI"100response = client.video.generate(101    prompt="Add rain and a moody atmosphere",102    model="grok-imagine-video",103    video_file_id="file_5be118c3-da55-31dd-76e7-a1b8c8d6355b",104)105```106107```bash108curl -s -X POST https://api.x.ai/v1/videos/edits \109  -H "Authorization: Bearer $XAI_API_KEY" \110  -H "Content-Type: application/json" \111  -d '{112    "model": "grok-imagine-video",113    "prompt": "Add rain and a moody atmosphere",114    "video": { "file_id": "file_5be118c3-da55-31dd-76e7-a1b8c8d6355b" }115  }'116```117118## Reference-to-video with multiple stored images119120```python customLanguage="pythonXAI"121response = client.video.generate(122    prompt="A woman in this dress walks down a city street at night",123    model="grok-imagine-video-1.5",124    duration=5,125    reference_image_file_ids=[126        "file_5be118c3-da55-31dd-76e7-a1b8c8d6355b",  # subject127        "file_2cd998e7-bf12-44aa-92c8-e3d1f1c1234f",  # outfit128    ],129)130```131132```bash133# Each reference_images entry independently carries url or file_id — mix kinds within a single request.134curl -s -X POST https://api.x.ai/v1/videos/generations \135  -H "Authorization: Bearer $XAI_API_KEY" \136  -H "Content-Type: application/json" \137  -d '{138    "model": "grok-imagine-video-1.5",139    "prompt": "A woman in this dress walks down a city street at night",140    "duration": 5,141    "reference_images": [142      { "file_id": "file_5be118c3-da55-31dd-76e7-a1b8c8d6355b" },143      { "url": "https://example.com/dress.jpg" }144    ]145  }'146```147148## Related149150* [Files API Integration](/developers/model-capabilities/imagine/files) — Overview + capstone example showing inputs and outputs together.151* [Persisting Generated Output](/developers/model-capabilities/imagine/files/outputs) — The output side: `storage_options`, public URLs, expiry semantics.152* [Managing Files](/developers/files/managing-files) — Upload, list, retrieve, update, and delete files.153
Files main
Menu

Theme