结合 Comfy Router 使用 Grok Imagine Video 1.5 Preview
通过 Comfy Router 调用 xai/grok-imagine-video-1.5-preview:端点、请求结构以及 Router 返回的响应。
结合 Comfy Router 使用 Grok Imagine Video 1.5 Preview
通过 Comfy Router 调用 xai/grok-imagine-video-1.5-preview:端点、请求结构以及 Router 返回的响应。
xai/grok-imagine-video-1.5-preview 的 API 参考文档,该模型由 Comfy Router 提供,源自 xAI。
输入: 文本, 图像 · 输出: 视频
快速开始
在你的 Comfy 工作区中创建密钥,并将其导出为 COMFY_API_KEY。Python 和 TypeScript 代码片段使用 Comfy SDK(pip install comfy-sdk 和 npm install @comfyorg/sdk);cURL 代码片段则是通过原生 HTTP 发起同一调用。
模型 ID: xai/grok-imagine-video-1.5-preview
端点: POST https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview
[tab] 等待结果 ``python Python theme={null} from comfy_sdk import Comfy # 从环境中读取 COMFY_API_KEY。 # SDK 会自动创建一个幂等键,并在自动重试时复用它。 with Comfy() as client: result = client.models.run( "xai/grok-imagine-video-1.5-preview", { "duration": 4, "prompt": "a single red maple leaf falling onto still water, slow motion", }, ) print(result)``typescript TypeScript theme={null} import { comfy } from "@comfyorg/sdk"; // 从环境中读取 COMFY_API_KEY。 // SDK 会自动创建一个幂等键,并在自动重试时复用它。 const { data } = await comfy.models.run("xai/grok-imagine-video-1.5-preview", { duration: 4, prompt: "a single red maple leaf falling onto still water, slow motion", }); console.log(data);``bash cURL theme={null} curl https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"duration\": 4, \"prompt\": \"a single red maple leaf falling onto still water, slow motion\"}"``
[tab] 入队并稍后收集 将相同的请求体发送到POST https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview/requests。运行被受理后,Router 会立即返回201和request_id;结果就绪后,可以从本进程或其他进程收集。状态、取消与收集的细节见 队列投递。 ``python Python theme={null} import asyncio from comfy_sdk import AsyncComfy # 从环境中读取 COMFY_API_KEY。 # 每次 submit() 调用都会生成自己的 Idempotency-Key,并在自动重试时复用它。 async def main(): async with AsyncComfy() as client: handle = await client.models.submit( "xai/grok-imagine-video-1.5-preview", { "duration": 4, "prompt": "a single red maple leaf falling onto still water, slow motion", }, ) print("request_id:", handle.request_id) # 配合模型 ID,这就是另一个进程所需的全部信息 # 轮询直到请求完成,按服务器指定的 Retry-After 等待。 async for update in handle.iter_events(): print(update.status, update.queue_position) # 提供商自身的负载,与 models.run() 返回的值相同。 # 失败或已取消的请求会在此处抛出带类型的 Router 错误。 result = await handle.get() print(result) asyncio.run(main())``typescript TypeScript theme={null} import { comfy } from "@comfyorg/sdk"; // 从环境中读取 COMFY_API_KEY。 // 每次 submit() 调用都会生成自己的 Idempotency-Key,并在自动重试时复用它。 const handle = await comfy.models.submit("xai/grok-imagine-video-1.5-preview", { duration: 4, prompt: "a single red maple leaf falling onto still water, slow motion", }); console.log("requestId:", handle.requestId); // 配合模型 ID,这就是另一个进程所需的全部信息 // 轮询直到请求完成,按服务器指定的 Retry-After 等待。 for await (const update of handle.events()) { console.log(update.status, update.queuePosition); } // 与 models.run() 返回的结果相同。失败或已取消的请求会在此处 reject。 const result = await handle.get(); console.log(result.data);``bash cURL theme={null} # 1. 提交。Router 返回 201,并附带 request_id、status_url、response_url 和 cancel_url。 curl https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview/requests \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"duration\": 4, \"prompt\": \"a single red maple leaf falling onto still water, slow motion\"}" # 2. 轮询直到状态为 COMPLETED,按每个响应指定的 Retry-After 秒数等待。 REQUEST_ID="<request_id from the 201 body>" curl -i https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview/requests/$REQUEST_ID/status \ -H "X-API-Key: $COMFY_API_KEY" # 3. 收集。完成后返回 200 和模型的原生输出,仍在运行时返回 202 和状态响应体。 curl https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview/requests/$REQUEST_ID \ -H "X-API-Key: $COMFY_API_KEY"``
Schema
输入
aspect\_ratio string (default: "16:9")
已生成视频的宽高比
可能的值:1:1、16:9、9:16、4:3、3:4、3:2、2:3
duration integer (default: 8)
视频时长,单位为秒。范围 \[1, 15]。默认 8。
范围:1 到 15
image object
xAI 端点使用的输入图像对象
image.type string
图像输入的类型
可能的值:image_url
image.url string required
输入图像的 URL(公开 URL 或 base64 编码的 data URI)
model string
要使用的模型。支持:grok-imagine-video(默认)、grok-imagine-video-1.5-preview、grok-imagine-video-1.5、grok-imagine-video-1.5-lite。已弃用的 grok-imagine-video-beta ID 是 grok-imagine-video 的别名。
output object
已生成视频的可选输出目标
prompt string required
用于视频生成的提示词。最多 4,096 个字符。
reference\_images object[]
用于引导视频生成的一张或多张参考图像(参考生视频模式)。与 image 互斥。Router 仅转发 application/json,该对象和 XAIImageObject 都不接受 file\_id,因此此路由不支持基于文件的图像输入。
reference\_images\[].url string required
参考图像的 URL。支持 HTTPS URL(公开)或 base64 编码的 data URL(例如 data:image/jpeg;base64,...)。
resolution string
输出视频的分辨率
size string
输出视频的尺寸
user string
代表最终用户的唯一标识符
本页内容根据 Router 在 GET /v2/models/xai/grok-imagine-video-1.5-preview/openapi.json 提供的 schema 生成,在请求到达提供商之前,Router 校验调用时依据的也是这份同一文档。
输出
block\_reason string
在本文档中绝不会携带原因:非空的 block 原因属于输入审核拒绝,Router 会以 Comfy Router 错误的形式作答,而不是返回此响应体。在本文档中为缺失、null 或空。
model string
用于生成视频的模型
status string
在本文档中缺失或为 done。pending 是 Router 尚未完成的轮询响应体,绝不会作为 200 返回;当 video.url 已填充时,Router 接受缺失的 status,因此调用方不得将其视为必需。
可能的值:done
usage object
视频生成请求的用量信息
usage.cost\_in\_usd\_ticks integer
此请求的费用,以 USD tick 表示。1 美分等于 100,000,000 ticks,因此 1 美元等于 10,000,000,000 ticks。
video object required
已完成的生成结果。与轮询文档不同,此处为必填:对于没有 video.url 的终端结果,会以 Comfy Router 错误的形式作答,因此 200 始终会携带它。
video.duration integer
已生成视频的时长,单位为秒
video.respect\_moderation boolean
模型生成的视频是否遵守审核规则
video.url string required
在本文档中为非空。只有当此叶子字段已填充时,Router 才报告成功;它是上文所述的重新托管的 Comfy 签名 URL,或者在无法执行重新托管时,为 xAI 自己的短期 URL。
示例
输入
{
"duration": 4,
"prompt": "a single red maple leaf falling onto still water, slow motion"
}
输出
{
"model": "grok-imagine-video-1.5",
"status": "done",
"usage": {
"cost_in_usd_ticks": 3500000000
},
"video": {
"duration": 4,
"respect_moderation": true,
"url": "https://example.invalid/xai/grok-imagine-video/generated.mp4"
}
}
发布前须知
SDK 会生成 Idempotency-Key 并在自动重试中复用它。手动重试时,请复用原始 key。Router 最长可保持连接 10 分钟。
请求失败时,Router 会发送 X-Comfy-Error-Type 响应头说明原因。422 表示 Router 在调用提供商之前就拒绝了输入,413 表示请求体超出了 Router 可接受的大小。已生成的资源请及时下载,因为结果 URL 会过期。
上文任何字段描述中提到的尺寸限制,都是提供商对该字段自身的限定,引自提供商的规范。Router 会对整个请求体另行设置上限,base64 编码的媒体内容也计入其中:参见请求体大小。
本页记录的是通过 Comfy Router 调用的某一个合作伙伴模型。同一个 comfy-sdk / @comfyorg/sdk 包还提供第二个客户端,用于在 Comfy Cloud 上运行完整的 ComfyUI 工作流图:Comfy(api_key=...) / new Comfy({ apiKey }),并带有 client.workflows、client.assets 和 client.jobs。请参阅 Comfy SDKs。
[card] 请求头 身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。
[card] 使用 Router API 模型发现、验证错误、重试与计费。
[card] 限制 Router 目前不支持的功能,以及替代方案。