> ## Documentation Index
> Fetch the complete documentation index at: https://docs.comfy.org/llms.txt
> Use this file to discover all available pages before exploring further.

# 通过 Comfy Router 使用 Pika H3 Flex 参考生视频

> 通过 Comfy Router 调用 pika/pika-h3-flex-reference-to-video：端点、请求结构以及 Router 返回的响应。

`pika/pika-h3-flex-reference-to-video` 的 API 参考文档，由 Comfy Router 从 Pika 提供。

**输入：** 文本、图像、视频、音频 · **输出：** 视频 + 音频

## 快速开始

在[你的 Comfy 工作区](https://platform.comfy.org/profile/api-keys?onboarding=router)中创建密钥，并将其导出为 `COMFY_API_KEY`。Python 和 TypeScript 代码片段使用 Comfy SDK（`pip install comfy-sdk` 和 `npm install @comfyorg/sdk`）；cURL 代码片段通过原始 HTTP 执行相同的调用。

**模型 ID：** `pika/pika-h3-flex-reference-to-video`

**端点：** `POST https://api.comfy.org/v2/models/pika/pika-h3-flex-reference-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-reference-to-video",
>         {
>             "duration": 5,
>             "prompt": "The woman from the first image walks through the market from the video, humming the tune from the audio",
>             "references": [
>                 {
>                     "type": "image",
>                     "url": "https://example.invalid/pika/character.png",
>                 },
>             ],
>             "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-reference-to-video", {
>   duration: 5,
>   prompt: "The woman from the first image walks through the market from the video, humming the tune from the audio",
>   references: [
>     {
>       type: "image",
>       url: "https://example.invalid/pika/character.png",
>     },
>   ],
>   resolution: "480p",
> });
>
> console.log(data);
> ```
>
> ```bash cURL theme={null}
> curl https://api.comfy.org/v2/models/pika/pika-h3-flex-reference-to-video \
>   -H "X-API-Key: $COMFY_API_KEY" \
>   -H "Idempotency-Key: $(uuidgen)" \
>   -H "Content-Type: application/json" \
>   -d "{\"duration\": 5, \"prompt\": \"The woman from the first image walks through the market from the video, humming the tune from the audio\", \"references\": [{\"type\":\"image\",\"url\":\"https://example.invalid/pika/character.png\"}], \"resolution\": \"480p\"}"
> ```

> [tab] 加入队列并稍后收集
>
> 同一个请求体，发送到 `POST https://api.comfy.org/v2/models/pika/pika-h3-flex-reference-to-video/requests`。运行一经接纳，Router 便返回 `201` 和 `request_id`；结果一旦就绪，即可从当前进程或其他进程收集。[队列交付](https://docs.comfy.org/zh/development/comfy-router/queue.md) 介绍了状态、取消和结果收集。
>
> ```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-reference-to-video",
>             {
>                 "duration": 5,
>                 "prompt": "The woman from the first image walks through the market from the video, humming the tune from the audio",
>                 "references": [
>                     {
>                         "type": "image",
>                         "url": "https://example.invalid/pika/character.png",
>                     },
>                 ],
>                 "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-reference-to-video", {
>   duration: 5,
>   prompt: "The woman from the first image walks through the market from the video, humming the tune from the audio",
>   references: [
>     {
>       type: "image",
>       url: "https://example.invalid/pika/character.png",
>     },
>   ],
>   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-reference-to-video/requests \
>   -H "X-API-Key: $COMFY_API_KEY" \
>   -H "Idempotency-Key: $(uuidgen)" \
>   -H "Content-Type: application/json" \
>   -d "{\"duration\": 5, \"prompt\": \"The woman from the first image walks through the market from the video, humming the tune from the audio\", \"references\": [{\"type\":\"image\",\"url\":\"https://example.invalid/pika/character.png\"}], \"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-reference-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-reference-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`

**output\_mode** `string` (default: "video")

`video` 仅返回视频。`audio-stems` 还会在 `output.stems` 中返回对白、音乐和音效的 WAV 分轨，并额外收取 Pika 按秒计费的分轨分离费用。

可选值：`video`、`audio-stems`

**prompt** `string` *required*

描述视频及其音频的文本提示词。

**references** `object[]` *required*

有序的参考媒体：最多 9 张图像、3 个视频和 3 个音频文件，共 12 个。至少需要一个图像或视频。每个文件最大 24 MiB。视频和音频片段时长为 2 至 15 秒，每种类型的总时长最多 15 秒。Pika 除了输出秒数外，还会对参考视频秒数计费。

**references\[].type** `string` *required*

文件的媒体类型。

可选值：`image`、`video`、`audio`

**references\[].url** `string` *required*

参考文件的 URL。图像为 PNG、JPEG 或 WebP。

**resolution** `string` (default: "768p")

输出分辨率。480p 和 768p 为原生分辨率。1080p、2k 和 4k 会以 768p 生成，然后再执行 upscale，同时保留音频和帧率。

可选值：`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-reference-to-video/openapi.json` 提供的 schema 生成，该 schema 也是它在请求到达提供商之前用于校验调用的同一份文档。

### 输出

**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 针对该任务报告的单位。

## 示例

### 输入

```json theme={null}
{
  "duration": 5,
  "prompt": "The woman from the first image walks through the market from the video, humming the tune from the audio",
  "references": [
    {
      "type": "image",
      "url": "https://example.invalid/pika/character.png"
    }
  ],
  "resolution": "480p"
}
```

### 输出

```json theme={null}
{
  "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 会过期](https://docs.comfy.org/zh/development/comfy-router/reference.md#结果资产)。

上文任何字段描述中提到的尺寸限制，都是提供商对该字段自身的限定，引自提供商的规范。Router 会对整个请求体另行设置上限，base64 编码的媒体内容也计入其中：参见[请求体大小](https://docs.comfy.org/zh/development/comfy-router/limitations.md)。

本页记录的是通过 Comfy Router 调用的某一个合作伙伴模型。同一个 `comfy-sdk` / `@comfyorg/sdk` 包还提供第二个客户端，用于在 Comfy Cloud 上运行完整的 ComfyUI 工作流图：`Comfy(api_key=...)` / `new Comfy({ apiKey })`，并带有 `client.workflows`、`client.assets` 和 `client.jobs`。请参阅 [Comfy SDKs](https://docs.comfy.org/zh/development/api-development/sdks.md)。

> [card] [请求头](https://docs.comfy.org/zh/development/comfy-router/headers.md)
>
> 身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。

> [card] [使用 Router API](https://docs.comfy.org/zh/development/comfy-router/api.md)
>
> 模型发现、验证错误、重试与计费。

> [card] [限制](https://docs.comfy.org/zh/development/comfy-router/limitations.md)
>
> Router 目前不支持的功能，以及替代方案。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.