从写代码,到创作下一幕

探索 字节跳动 - 火山方舟 的 AI 编程与视频创作活动。

火山方舟 Agent Plan 与 Coding Plan 活动,价格 ¥9.9 起

Agent Plan & Coding Plan

一站体验多款热门模型,为 AI 编程与智能体开发提供更多选择。新用户可联系(微信: goo_lvyouyou)免费体验 9.9 agent plan。

查看套餐优惠
Seedance 2.5 视频创作活动:30 秒视频、多模态参考、局部编辑

Seedance 2.5

让创意,跃然成片。探索 30 秒视频、多模态参考与局部编辑,把脑海中的画面变成下一支作品。

探索视频创作

模型能力

Files API 集成

查看 Markdown

Imagine API 可从两个方向与 Files API 集成:

默认情况下,Imagine 请求会在 临时 上返回一个 imgen.x.ai,或在 vidgen.x.ai 临时 URL,它只能在生成后的短时间内用于获取资产。Files 集成让你可以在同一次请求中复用已存储的输入并持久保存输出。


组合使用:迭代循环

同时使用输入和输出最直接的收益,是可以始终通过 Files API 串联 Imagine 调用。直接引用已存储的 file_id,例如上一次调用的 file_output,无需下载、重新上传或将文件设为公开。

Python

import os
import xai_sdk

client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))

# 1. Generate an image and store it
gen = client.image.sample(
    prompt="A futuristic city skyline at night",
    model="grok-imagine-image-2.0",
    storage_options={"filename": "city.jpg"},  # store privately, no public URL needed
)
city = gen.file_output.file_id

# 2. Edit the stored image without re-uploading
edit = client.image.sample(
    prompt="Add neon signs to the buildings",
    model="grok-imagine-image-2.0",
    image_file_id=city,
    storage_options={"filename": "city-neon.jpg"},
)

# 3. Animate the edited result into a video
vid = client.video.generate(
    prompt="A camera pulls back through the city",
    model="grok-imagine-video-1.5",
    duration=5,
    image_file_id=edit.file_output.file_id,
)

print(vid.url)


最后更新:2026 年 10 月 19 日