> ## 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 Reference To Video を使用する

> 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/ja/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 は request_id、status_url、response_url、cancel_url を含む 201 を返します。
> 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. 取得。実行中はステータスボディ付きの 202、完了時はモデルのネイティブ出力付きの 200 を返します。
> curl https://api.comfy.org/v2/models/pika/pika-h3-flex-reference-to-video/requests/$REQUEST_ID \
>   -H "X-API-Key: $COMFY_API_KEY"
> ```

## スキーマ

### 入力

**aspect\_ratio** `string`

出力のアスペクト比。`auto` はプロンプトとメディア入力から1つを選びます。省略すると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` は Dialogue、Music、Effect のWAVステムを `output.stems` に追加で返し、Pikaの秒単位のステム分離料金が加算されます。

指定可能な値: `video`, `audio-stems`

**prompt** `string` *required*

ビデオとそのオーディオを説明するテキストプロンプト。

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

順序付きの参照メディア。画像は最大9件、ビデオは最大3件、オーディオファイルは最大3件、合計12件までです。少なくとも1つの画像またはビデオが必須です。各ファイルは最大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で生成してからアップスケールし、オーディオとフレームレートを維持します。

指定可能な値: `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` で提供するスキーマから生成されています。これは、リクエストがプロバイダーに到達する前に呼び出しを検証するのと同じドキュメントです。

### 出力

**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`

生成済みメディアファイル1件。

**output.audio.content\_type** `string`

ファイルのMIMEタイプ。

**output.audio.url** `string`

生成済みファイルのダウンロードURL。

**output.media\_type** `string`

ファイルを格納するフィールド: video または audio。

**output.video** `object`

生成済みメディアファイル1件。

**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` を生成し、自動リトライで再利用します。手動リトライでは元のキーを再利用してください。Router は最大 10 分間接続を保持できます。

リクエストが失敗すると、Router は理由を説明する `X-Comfy-Error-Type` レスポンスヘッダーを送信します。`422` は、プロバイダーを呼び出す前に Router が入力を拒否したことを意味し、`413` はリクエスト本文が Router の受け入れ可能なサイズを超えていたことを意味します。生成されたアセットは [結果 URL の有効期限](https://docs.comfy.org/ja/development/comfy-router/reference.md#結果アセット) があるため、早めにダウンロードしてください。

上記のフィールド説明に記載されているサイズ制限は、プロバイダーの仕様から引用した、そのフィールドに対するプロバイダー自身の上限です。Router はリクエスト本文全体に対して別の上限を適用し、base64 エンコードされたメディアもこれにカウントされます。[リクエスト本文のサイズ](https://docs.comfy.org/ja/development/comfy-router/limitations.md) を参照してください。

このページは、Comfy Router 経由で呼び出す 1 つのパートナーモデルについて説明しています。同じ `comfy-sdk` / `@comfyorg/sdk` パッケージには、Comfy Cloud 上で ComfyUI のワークフローグラフ全体を実行するための 2 つ目のクライアントも含まれています: `Comfy(api_key=...)` / `new Comfy({ apiKey })`、および `client.workflows`、`client.assets`、`client.jobs`。[Comfy SDKs](https://docs.comfy.org/ja/development/api-development/sdks.md) を参照してください。

> [card] [ヘッダー](https://docs.comfy.org/ja/development/comfy-router/headers.md)
>
> 認証、冪等性、リクエスト ID、エラー分類、リトライ間隔、支出上限。

> [card] [Router API の利用](https://docs.comfy.org/ja/development/comfy-router/api.md)
>
> モデルの検出、バリデーションエラー、リトライ、課金。

> [card] [制限事項](https://docs.comfy.org/ja/development/comfy-router/limitations.md)
>
> Router が現在対応していないことと、代替手段。


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