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

> Comfy Router 経由で pika/pika-2.5-image-to-video を呼び出します: エンドポイント、リクエストの形状、Router が返すレスポンス。

`pika/pika-2.5-image-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-2.5-image-to-video`

**エンドポイント:** `POST https://api.comfy.org/v2/models/pika/pika-2.5-image-to-video`

<Tabs defaultTabIndex={1}>
  <Tab title="結果を待つ">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # 環境変数から COMFY_API_KEY を読み取ります。
      # SDK は自動的に冪等性キーを作成し、自動リトライのために再利用します。
      with Comfy() as client:
          result = client.models.run(
              "pika/pika-2.5-image-to-video",
              {
                  "duration_s": 5,
                  "image": "https://example.invalid/pika/source.png",
                  "prompt": "The camera slowly pushes in as the leaves begin to sway",
                  "resolution": "720p",
              },
          )

      print(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // 環境変数から COMFY_API_KEY を読み取ります。
      // SDK は自動的に冪等性キーを作成し、自動リトライのために再利用します。
      const { data } = await comfy.models.run("pika/pika-2.5-image-to-video", {
        duration_s: 5,
        image: "https://example.invalid/pika/source.png",
        prompt: "The camera slowly pushes in as the leaves begin to sway",
        resolution: "720p",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/pika/pika-2.5-image-to-video \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"duration_s\": 5, \"image\": \"https://example.invalid/pika/source.png\", \"prompt\": \"The camera slowly pushes in as the leaves begin to sway\", \"resolution\": \"720p\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="キューに送信して後で収集する">
    同じボディを `POST https://api.comfy.org/v2/models/pika/pika-2.5-image-to-video/requests` に送信します。Router は実行が受け付けられるとすぐに `201` と `request_id` を返し、結果は準備ができ次第、このプロセスからでも別のプロセスからでも収集できます。[キューの配信](/ja/development/comfy-router/queue)では、ステータス、キャンセル、収集について説明します。

    <CodeGroup>
      ```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-2.5-image-to-video",
                  {
                      "duration_s": 5,
                      "image": "https://example.invalid/pika/source.png",
                      "prompt": "The camera slowly pushes in as the leaves begin to sway",
                      "resolution": "720p",
                  },
              )
              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-2.5-image-to-video", {
        duration_s: 5,
        image: "https://example.invalid/pika/source.png",
        prompt: "The camera slowly pushes in as the leaves begin to sway",
        resolution: "720p",
      });
      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/pika/pika-2.5-image-to-video/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"duration_s\": 5, \"image\": \"https://example.invalid/pika/source.png\", \"prompt\": \"The camera slowly pushes in as the leaves begin to sway\", \"resolution\": \"720p\"}"

      # 2. status が COMPLETED になるまでポーリングし、各レスポンスが指定する Retry-After 秒だけ待機します。
      REQUEST_ID="<request_id from the 201 body>"
      curl -i https://api.comfy.org/v2/models/pika/pika-2.5-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-2.5-image-to-video/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## スキーマ

### 入力

<ParamField body="duration_s" type="integer" default="5">
  ビデオの長さ（秒）。

  指定可能な値: `5`、`10`
</ParamField>

<ParamField body="image" type="string" required>
  アニメートするソース画像の公開 https URL。この画像が被写体を担います。平文の `http://` は拒否されます。Pika は Comfy のキーで送信されたリクエストで URL を取得します。
</ParamField>

<ParamField body="negative_prompt" type="string">
  ビデオで避けたい内容を記述したテキスト。
</ParamField>

<ParamField body="prompt" type="string">
  動きを導くテキストプロンプト。
</ParamField>

<ParamField body="resolution" type="string" default="&#x22;1080p&#x22;">
  出力解像度。

  指定可能な値: `720p`、`1080p`
</ParamField>

<ParamField body="seed" type="integer">
  再現可能な生成のためのシード。ランダムなシードを得るには省略します（または null を送信します）。
</ParamField>

Router が `GET /v2/models/pika/pika-2.5-image-to-video/openapi.json` で提供するスキーマから生成されています。これは、リクエストがプロバイダーに到達する前に Router が呼び出しを検証する対象となるドキュメントと同じものです。

### 出力

<ResponseField name="error" type="object">
  Pika の構造化された失敗記録で、`failed` ジョブに設定されます。Router は失敗したジョブに対して独自のエラー応答を返すため、Router が返すボディにこれが含まれることはありません。これは Pika のジョブドキュメントの一部であるため宣言されています。
</ResponseField>

<ResponseField name="error.code" type="string" required>
  指定可能な値: `invalid_input`、`content_moderation`、`provider_error`、`provider_timeout`、`provider_unavailable`、`rate_limited`、`insufficient_balance`、`membership_required`、`cycle_limit_exceeded`、`admission_suspended`、`usage_limit_exceeded`、`timed_out`、`internal`
</ResponseField>

<ResponseField name="error.message" type="string" required />

<ResponseField name="id" type="string" required>
  Pika のジョブID。
</ResponseField>

<ResponseField name="model_id" type="string">
  ジョブが実行した Pika カタログのエントリ。
</ResponseField>

<ResponseField name="output" type="object">
  完了したジョブのメディアで、`status` が `completed` のときに設定されます。`media_type` はどのフィールドにメディアが入るかを示します。`image` なら `images`、`video` なら `video`、`videos` なら `videos` です。
</ResponseField>

<ResponseField name="output.images" type="object[]">
  画像モデルの場合の、生成済みの画像。
</ResponseField>

<ResponseField name="output.images[].content_type" type="string">
  ファイルの MIME タイプ。
</ResponseField>

<ResponseField name="output.images[].height" type="integer">
  高さ（ピクセル単位）。
</ResponseField>

<ResponseField name="output.images[].url" type="string">
  生成済みファイルのダウンロード URL。
</ResponseField>

<ResponseField name="output.images[].width" type="integer">
  幅（ピクセル単位）。
</ResponseField>

<ResponseField name="output.media_type" type="string">
  指定可能な値: `image`、`video`、`videos`
</ResponseField>

<ResponseField name="output.seed" type="integer">
  ビデオジョブが実際に使用したシード（報告された場合）。
</ResponseField>

<ResponseField name="output.video" type="object">
  生成されたメディアファイル1つ。
</ResponseField>

<ResponseField name="output.video.content_type" type="string">
  ファイルの MIME タイプ。
</ResponseField>

<ResponseField name="output.video.height" type="integer">
  高さ（ピクセル単位）。
</ResponseField>

<ResponseField name="output.video.url" type="string">
  生成済みファイルのダウンロード URL。
</ResponseField>

<ResponseField name="output.video.width" type="integer">
  幅（ピクセル単位）。
</ResponseField>

<ResponseField name="output.videos" type="object[]">
  複数ビデオの配信の場合の、生成済みのビデオ。
</ResponseField>

<ResponseField name="output.videos[].content_type" type="string">
  ファイルの MIME タイプ。
</ResponseField>

<ResponseField name="output.videos[].height" type="integer">
  高さ（ピクセル単位）。
</ResponseField>

<ResponseField name="output.videos[].url" type="string">
  生成済みファイルのダウンロード URL。
</ResponseField>

<ResponseField name="output.videos[].width" type="integer">
  幅（ピクセル単位）。
</ResponseField>

<ResponseField name="runtime_s" type="number">
  生成にかかった秒数（ディスパッチから終端まで）。ベストエフォートであり、null になる場合があります。
</ResponseField>

<ResponseField name="status" type="string" required>
  ライフサイクルの状態。Router が返すボディは常に `completed` です。`failed` のジョブには代わりに Router のエラー応答が返されます。

  指定可能な値: `queued`、`running`、`completed`、`failed`
</ResponseField>

<ResponseField name="usage" type="object">
  ジョブについてプロバイダーが報告した単位。キーは疎で、ジョブが報告する単位のみが存在します。
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "duration_s": 5,
  "image": "https://example.invalid/pika/source.png",
  "prompt": "The camera slowly pushes in as the leaves begin to sway",
  "resolution": "720p"
}
```

### 出力

```json theme={null}
{
  "id": "2d8e4b71-9c05-4f3a-b6d2-81e7a5c09f44",
  "model_id": "pika/pika-2.5/image-to-video",
  "output": {
    "media_type": "video",
    "seed": 42,
    "video": {
      "content_type": "video/mp4",
      "height": 720,
      "url": "https://example.invalid/pika/pika-2.5-image-to-video/generated.mp4",
      "width": 1280
    }
  },
  "status": "completed"
}
```

## 出荷前の確認

SDK は `Idempotency-Key` を生成し、自動リトライで再利用します。手動リトライでは元のキーを再利用してください。Router は最大 10 分間接続を保持できます。

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

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

このページは、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](/ja/development/api-development/sdks) を参照してください。

<CardGroup cols={3}>
  <Card title="ヘッダー" icon="list" href="/ja/development/comfy-router/headers">
    認証、冪等性、リクエスト ID、エラー分類、リトライ間隔、支出上限。
  </Card>

  <Card title="Router API の利用" icon="code" href="/ja/development/comfy-router/api">
    モデルの検出、バリデーションエラー、リトライ、課金。
  </Card>

  <Card title="制限事項" icon="triangle-exclamation" href="/ja/development/comfy-router/limitations">
    Router が現在対応していないことと、代替手段。
  </Card>
</CardGroup>


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