通过 Comfy Router 使用 Pika H3 Flex 图生视频
通过 Comfy Router 调用 pika/pika-h3-flex-image-to-video:端点、请求形状以及 Router 返回的响应。
通过 Comfy Router 使用 Pika H3 Flex 图生视频
通过 Comfy Router 调用 pika/pika-h3-flex-image-to-video:端点、请求形状以及 Router 返回的响应。
pika/pika-h3-flex-image-to-video 的 API 参考,由 Comfy Router 从 Pika 提供。
输入: 文本、图像 · 输出: 视频 + 音频
快速开始
在你的 Comfy 工作区中创建密钥,并将其导出为 COMFY_API_KEY。Python 和 TypeScript 代码片段使用 Comfy SDK(pip install comfy-sdk 和 npm install @comfyorg/sdk);cURL 代码片段是通过原始 HTTP 发起的相同调用。
模型 ID: pika/pika-h3-flex-image-to-video
端点: POST https://api.comfy.org/v2/models/pika/pika-h3-flex-image-to-video
[tab] 等待结果 ``python Python theme={null} from comfy_sdk import Comfy # 从环境变量读取 COMFY_API_KEY。 # SDK 会自动创建幂等键,并在自动重试时复用它。 with Comfy() as client: result = client.models.run( "pika/pika-h3-flex-image-to-video", { "duration": 5, "image": "https://example.invalid/pika/first-frame.png", "prompt": "The camera slowly pushes in as the leaves begin to sway in the wind", "resolution": "480p", }, ) print(result)``typescript TypeScript theme={null} import { comfy } from "@comfyorg/sdk"; // 从环境变量读取 COMFY_API_KEY。 // SDK 会自动创建幂等键,并在自动重试时复用它。 const { data } = await comfy.models.run("pika/pika-h3-flex-image-to-video", { duration: 5, image: "https://example.invalid/pika/first-frame.png", prompt: "The camera slowly pushes in as the leaves begin to sway in the wind", resolution: "480p", }); console.log(data);``bash cURL theme={null} curl https://api.comfy.org/v2/models/pika/pika-h3-flex-image-to-video \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"duration\": 5, \"image\": \"https://example.invalid/pika/first-frame.png\", \"prompt\": \"The camera slowly pushes in as the leaves begin to sway in the wind\", \"resolution\": \"480p\"}"``
[tab] 加入队列,稍后收集 相同的请求体,发送到POST https://api.comfy.org/v2/models/pika/pika-h3-flex-image-to-video/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( "pika/pika-h3-flex-image-to-video", { "duration": 5, "image": "https://example.invalid/pika/first-frame.png", "prompt": "The camera slowly pushes in as the leaves begin to sway in the wind", "resolution": "480p", }, ) 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("pika/pika-h3-flex-image-to-video", { duration: 5, image: "https://example.invalid/pika/first-frame.png", prompt: "The camera slowly pushes in as the leaves begin to sway in the wind", resolution: "480p", }); console.log("requestId:", handle.requestId); // 再加上模型 ID,就是另一个进程所需的全部信息 // 轮询直到请求完成,等待服务器指定的 Retry-After。 for await (const update of handle.events()) { console.log(update.status, update.queuePosition); } // 与 models.run() 返回的结果相同。失败或已取消的请求会在这里被拒绝。 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/pika/pika-h3-flex-image-to-video/requests \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"duration\": 5, \"image\": \"https://example.invalid/pika/first-frame.png\", \"prompt\": \"The camera slowly pushes in as the leaves begin to sway in the wind\", \"resolution\": \"480p\"}" # 2. 轮询直到状态为 COMPLETED,等待每次响应指定的 Retry-After 秒数。 REQUEST_ID="<request_id from the 201 body>" curl -i https://api.comfy.org/v2/models/pika/pika-h3-flex-image-to-video/requests/$REQUEST_ID/status \ -H "X-API-Key: $COMFY_API_KEY" # 3. 收集。返回 200 时包含模型的原生输出;仍在运行时返回 202 和状态响应体。 curl https://api.comfy.org/v2/models/pika/pika-h3-flex-image-to-video/requests/$REQUEST_ID \ -H "X-API-Key: $COMFY_API_KEY"``
Schema
输入
aspect\_ratio string
输出宽高比。auto 会从提示词和媒体输入中挑选一个。省略此项则由 Pika 决定:当 rewrite 开启时为 auto,否则取第一个媒体输入的比例,再否则为 16:9。
可选值:auto、21:9、16:9、3:2、4:3、5:4、1:1、4:5、3:4、2:3、9:16、9:21
channel\_mode string (default: "mono")
仅用于音频分轨。mono 会先做下混再分离;stereo 保留两个声道。视频中的音频不受影响。
可选值:stereo、mono
duration integer (default: 5)
视频时长,以整秒为单位,取值 5 到 15。
范围:5 到 15
image string
首帧图像的 URL,需为静态 JPEG、PNG 或 WebP,最大 24 MiB、4000 万像素。
last\_frame\_image string
尾帧图像的 URL,格式和大小限制与 image 相同。
output\_mode string (default: "video")
video 只返回视频。audio-stems 还会在 output.stems 中返回 Dialogue、Music 和 Effect 的 WAV 分轨,并额外收取 Pika 按秒计费的分轨分离费用。
可选值:video、audio-stems
prompt string required
描述视频及其音频的文本提示词。
resolution string (default: "768p")
输出分辨率。480p 和 768p 为原生分辨率。1080p、2k 和 4k 会先以 768p 生成再放大,同时保留音频和帧率。
可选值:480p、768p、1080p、2k、4k
rewrite boolean (default: true)
在生成之前优化提示词。将其设为 false 即可按原样使用提示词。
seed integer (default: 0)
视频的种子,取值 0 或更大。
范围:0 到 …
格式:int64
该文档由 Router 在 GET /v2/models/pika/pika-h3-flex-image-to-video/openapi.json 提供的 schema 生成,Router 在请求到达提供商之前也会用同一份文档校验调用。
输出
error object
仅在 failed 任务上设置。
error.code string
机器可读的失败代码,例如 invalid\_input、content\_moderation 或 provider\_error。
error.message string
诊断文本。
id string
用于轮询状态的任务ID。
model\_id string
该任务所运行的 Pika 目录条目。
output object
已完成任务的媒体文件,在 status 为 completed 时设置。
output.audio object
一个已生成的媒体文件。
output.audio.content\_type string
文件的 MIME 类型。
output.audio.url string
已生成文件的下载 URL。
output.media\_type string
由哪个字段承载文件:video 或 audio。
output.video object
一个已生成的媒体文件。
output.video.content\_type string
文件的 MIME 类型。
output.video.url string
已生成文件的下载 URL。
status string
任务状态:queued、running、completed 或 failed。
usage object
Pika 为该任务上报的用量单位。
示例
输入
{
"duration": 5,
"image": "https://example.invalid/pika/first-frame.png",
"prompt": "The camera slowly pushes in as the leaves begin to sway in the wind",
"resolution": "480p"
}
输出
{
"id": "media_8f3a2c91-5b7d-4e0a-9c26-31d4f2a8e6b0",
"output": {
"media_type": "video",
"video": {
"content_type": "video/mp4",
"url": "https://example.invalid/pika/video.mp4"
}
},
"status": "completed"
}
发布前须知
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 目前不支持的功能,以及替代方案。