> ## 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.

# P Video 2 を Comfy Router で使用する

> pruna/p-video-2 を Comfy Router 経由で呼び出します。エンドポイント、リクエストの形状、Router が返すレスポンスについて説明します。

`pruna/p-video-2` の API リファレンス。Pruna の Comfy Router から提供されます。

## クイックスタート

[Comfy ワークスペース](https://platform.comfy.org/profile/api-keys)でキーを作成し、`COMFY_API_KEY` としてエクスポートします。Python と TypeScript のスニペットは Comfy SDK（`pip install comfy-sdk`、`npm install @comfyorg/sdk`）を使用しています。cURL のスニペットは、同じ呼び出しを生の HTTP で行うものです。

**モデル ID:** `pruna/p-video-2`

**エンドポイント:** `POST https://api.comfy.org/v2/models/pruna/p-video-2`

<Tabs>
  <Tab title="Wait for the result">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # The SDK automatically creates an idempotency key and reuses it for automatic retries.
      with Comfy() as client:
          result = client.models.run(
              "pruna/p-video-2",
              {
                  "input": {
                      "aspect_ratio": "16:9",
                      "draft": False,
                      "duration": 2,
                      "fps": 24,
                      "prompt": "A single red maple leaf resting on a plain white background.",
                      "resolution": "720p",
                  },
              },
          )

      print(result)
      ```

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

      // Reads COMFY_API_KEY from the environment.
      // The SDK automatically creates an idempotency key and reuses it for automatic retries.
      const { data } = await comfy.models.run("pruna/p-video-2", {
        input: {
          aspect_ratio: "16:9",
          draft: false,
          duration: 2,
          fps: 24,
          prompt: "A single red maple leaf resting on a plain white background.",
          resolution: "720p",
        },
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/pruna/p-video-2 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"aspect_ratio\":\"16:9\",\"draft\":false,\"duration\":2,\"fps\":24,\"prompt\":\"A single red maple leaf resting on a plain white background.\",\"resolution\":\"720p\"}}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Queue and collect later">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      with Comfy() as client:
          handle = client.models.submit(
              "pruna/p-video-2",
              {
                  "input": {
                      "aspect_ratio": "16:9",
                      "draft": False,
                      "duration": 2,
                      "fps": 24,
                      "prompt": "A single red maple leaf resting on a plain white background.",
                      "resolution": "720p",
                  },
              },
          )
          print("request_id:", handle.request_id)  # with the model ID, all another process needs

          # Poll until the request completes, waiting the Retry-After the server names.
          for update in handle.iter_events():
              print(update.status, update.queue_position)

          # The provider's own payload, the same value models.run() returns.
          # A request that failed or was cancelled raises the typed Router error here.
          result = handle.get()

      print(result)
      ```

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

      // Reads COMFY_API_KEY from the environment.
      // Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      const handle = await comfy.models.submit("pruna/p-video-2", {
        input: {
          aspect_ratio: "16:9",
          draft: false,
          duration: 2,
          fps: 24,
          prompt: "A single red maple leaf resting on a plain white background.",
          resolution: "720p",
        },
      });
      console.log("requestId:", handle.requestId); // with the model ID, all another process needs

      // Poll until the request completes, waiting the Retry-After the server names.
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // The same result models.run() returns. A request that failed or was cancelled rejects here.
      const result = await handle.get();

      console.log(result.data);
      ```

      ```bash cURL theme={null}
      # 1. Submit. Router answers 201 with request_id, status_url, response_url and cancel_url.
      curl https://api.comfy.org/v2/models/pruna/p-video-2/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"aspect_ratio\":\"16:9\",\"draft\":false,\"duration\":2,\"fps\":24,\"prompt\":\"A single red maple leaf resting on a plain white background.\",\"resolution\":\"720p\"}}"

      # 2. Poll until status is COMPLETED, waiting the Retry-After seconds each response names.
      REQUEST_ID="<request_id from the 201 body>"
      curl -i https://api.comfy.org/v2/models/pruna/p-video-2/requests/$REQUEST_ID/status \
        -H "X-API-Key: $COMFY_API_KEY"

      # 3. Collect. 200 with the model's native output, 202 with the status body while it is still running.
      curl https://api.comfy.org/v2/models/pruna/p-video-2/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## スキーマ

### 入力

<ParamField body="input" type="object" required>
  P-Video-2 の生成パラメータ。生成は完成したビデオの秒数に応じて課金され、返却されたファイルを基準に、`resolution` と `draft` で決まるレートで計算されます。セーフティフィルタは常に有効で、リクエスト内の `disable_safety_filter` の値は無視されます。
</ParamField>

<ParamField body="input.aspect_ratio" type="string" default="&#x22;16:9&#x22;">
  アスペクト比: 16:9、9:16、4:3、3:4、3:2、2:3 または 1:1。`image` が設定されている場合は無視されます。
</ParamField>

<ParamField body="input.audio" type="string">
  生成を条件付ける入力オーディオの URI（flac、mp3 または wav）。出力の長さはオーディオに従います。
</ParamField>

<ParamField body="input.draft" type="boolean" default="false">
  より高速で低品質なプレビュー。draft レートで課金されます。
</ParamField>

<ParamField body="input.duration" type="integer">
  生成されるビデオの再生時間（秒、1〜20）。省略した場合、モデルはプロンプトから長さを選択し、最大 20 秒になります。`audio` が設定されている場合は無視されます。

  範囲: `1` から `20`
</ParamField>

<ParamField body="input.fps" type="integer" default="24">
  フレームレート: 24 または 48。
</ParamField>

<ParamField body="input.image" type="string">
  画像から動画へ生成するための入力画像の URI（jpg、jpeg、png または webp）。
</ParamField>

<ParamField body="input.last_frame_image" type="string">
  最後のフレームの参照画像 URI。
</ParamField>

<ParamField body="input.prompt" type="string" required>
  ビデオ生成のためのテキストプロンプト。
</ParamField>

<ParamField body="input.prompt_upsampling" type="boolean" default="true">
  生成前にプロンプトを書き換えます。`seed` で結果を再現する必要がある場合は無効にしてください。
</ParamField>

<ParamField body="input.resolution" type="string" default="&#x22;720p&#x22;">
  出力解像度: 720p または 1080p。
</ParamField>

<ParamField body="input.save_audio" type="boolean" default="true">
  ビデオをオーディオ付きで保存します。
</ParamField>

<ParamField body="input.seed" type="integer">
  再現可能な生成のためのランダムシード。省略した場合はランダムになります。
</ParamField>

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

### 出力

<ResponseField name="error" type="string">
  エラーメッセージ。status が failed の場合に含まれます。
</ResponseField>

<ResponseField name="generation_url" type="string">
  完了したビデオの URL。status が succeeded の場合に含まれます。
</ResponseField>

<ResponseField name="message" type="string">
  人間が読める進捗メッセージ。
</ResponseField>

<ResponseField name="status" type="string">
  予測ステータス: starting、processing、succeeded、failed または canceled。
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "input": {
    "aspect_ratio": "16:9",
    "draft": false,
    "duration": 2,
    "fps": 24,
    "prompt": "A single red maple leaf resting on a plain white background.",
    "resolution": "720p"
  }
}
```

### 出力

```json theme={null}
{
  "generation_url": "https://example.invalid/pruna/p-video-2/output.mp4",
  "status": "succeeded"
}
```

## 出荷前の確認

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

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

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

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

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