模型能力
将文件引用为输入
只要 Imagine 端点接受公开 URL 或 Base64 编码的图像/视频,就可以改为传入 file_id(来自你的 Files API 存储)。文件会由服务端从你的私有存储中获取,因此:
无需耗费带宽重复上传同一张图像,这对迭代编辑循环很有帮助。
原始文件会保持私有(作为输入使用时无需将其设为公开)。
既适用于上传的文件,也适用于先前 Imagine 调用生成的资产(通过
storage_options)。
引用的文件必须是端点所要求的正确内容类型(图像:PNG/JPEG/WebP;视频:MP4),并且必须已完整上传。
编辑已存储的图像
curl -s -X POST https://api.x.ai/v1/images/edits \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-image-2.0",
"prompt": "Add a party hat to the dog",
"image": { "file_id": "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a" },
"response_format": "url"
}'使用多张已存储图像进行编辑
# Each images entry independently carries url or file_id — mix kinds within a single request.
curl -s -X POST https://api.x.ai/v1/images/edits \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-image-2.0",
"prompt": "Blend these two scenes into one cohesive composition",
"images": [
{ "file_id": "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a" },
{ "url": "https://example.com/scene-b.jpg" }
],
"response_format": "url"
}'使用已存储首帧生成视频
curl -s -X POST https://api.x.ai/v1/videos/generations \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video-1.5",
"prompt": "Pan across the scene as the sky darkens",
"duration": 5,
"image": { "file_id": "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a" }
}'编辑已存储的视频
curl -s -X POST https://api.x.ai/v1/videos/edits \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video",
"prompt": "Add rain and a moody atmosphere",
"video": { "file_id": "file_5be118c3-da55-31dd-76e7-a1b8c8d6355b" }
}'使用多张已存储图像进行参考图转视频
# Each reference_images entry independently carries url or file_id — mix kinds within a single request.
curl -s -X POST https://api.x.ai/v1/videos/generations \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video-1.5",
"prompt": "A woman in this dress walks down a city street at night",
"duration": 5,
"reference_images": [
{ "file_id": "file_5be118c3-da55-31dd-76e7-a1b8c8d6355b" },
{ "url": "https://example.com/dress.jpg" }
]
}'相关内容
Files API 集成:概览以及组合使用输入与输出的完整示例。
持久保存生成的输出:输出方向:
storage_options、公开 URL 和过期语义。管理文件:上传、列出、获取、更新和删除文件。
最后更新:2026 年 11 月 2 日