> ## 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 で Veo 3.1 Generate 001 を使う

> Comfy Router 経由で veo/veo-3.1-generate-001 を呼び出します: エンドポイント、リクエストの形状、Router が返すレスポンス。

`veo/veo-3.1-generate-001` の API リファレンス。Veo から 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:** `veo/veo-3.1-generate-001`

**エンドポイント:** `POST https://api.comfy.org/v2/models/veo/veo-3.1-generate-001`

<Tabs>
  <Tab title="結果を待つ">
    <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(
              "veo/veo-3.1-generate-001",
              {
                  "instances": [
                      {
                          "prompt": "a single red maple leaf falling onto still water, slow motion",
                      },
                  ],
                  "parameters": {
                      "durationSeconds": 4,
                      "generateAudio": False,
                      "sampleCount": 1,
                  },
              },
          )

      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("veo/veo-3.1-generate-001", {
        instances: [
          {
            prompt: "a single red maple leaf falling onto still water, slow motion",
          },
        ],
        parameters: {
          durationSeconds: 4,
          generateAudio: false,
          sampleCount: 1,
        },
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/veo/veo-3.1-generate-001 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"instances\": [{\"prompt\":\"a single red maple leaf falling onto still water, slow motion\"}], \"parameters\": {\"durationSeconds\":4,\"generateAudio\":false,\"sampleCount\":1}}"
      ```
    </CodeGroup>
  </Tab>

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

    <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(
              "veo/veo-3.1-generate-001",
              {
                  "instances": [
                      {
                          "prompt": "a single red maple leaf falling onto still water, slow motion",
                      },
                  ],
                  "parameters": {
                      "durationSeconds": 4,
                      "generateAudio": False,
                      "sampleCount": 1,
                  },
              },
          )
          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("veo/veo-3.1-generate-001", {
        instances: [
          {
            prompt: "a single red maple leaf falling onto still water, slow motion",
          },
        ],
        parameters: {
          durationSeconds: 4,
          generateAudio: false,
          sampleCount: 1,
        },
      });
      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/veo/veo-3.1-generate-001/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"instances\": [{\"prompt\":\"a single red maple leaf falling onto still water, slow motion\"}], \"parameters\": {\"durationSeconds\":4,\"generateAudio\":false,\"sampleCount\":1}}"

      # 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/veo/veo-3.1-generate-001/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/veo/veo-3.1-generate-001/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## スキーマ

### 入力

<ParamField body="instances" type="object[]" />

<ParamField body="instances[].cameraControl" type="string">
  カメラのモーションタイプ。画像の指定が必要です。

  指定可能な値: `fixed`、`pan_left`、`pan_right`、`tilt_up`、`tilt_down`、`truck_left`、`truck_right`、`pedestal_up`、`pedestal_down`、`push_in`、`pull_out`
</ParamField>

<ParamField body="instances[].image" type="object">
  ビデオ生成をガイドするためのオプションの先頭フレーム画像
</ParamField>

<ParamField body="instances[].image.bytesBase64Encoded" type="string (byte)">
  Base64 でエンコードされた画像データ

  形式: `byte`
</ParamField>

<ParamField body="instances[].image.gcsUri" type="string">
  画像の Cloud Storage URI
</ParamField>

<ParamField body="instances[].image.mimeType" type="string">
  画像の MIME タイプ (image/jpeg または image/png)

  指定可能な値: `image/jpeg`、`image/png`
</ParamField>

<ParamField body="instances[].lastFrame" type="object">
  オプションの末尾フレーム画像。image と併用して先頭フレームと末尾フレームの間のビデオを生成します。Veo 3.0 以降のモデルでサポートされています。
</ParamField>

<ParamField body="instances[].lastFrame.bytesBase64Encoded" type="string (byte)">
  Base64 でエンコードされた画像データ

  形式: `byte`
</ParamField>

<ParamField body="instances[].lastFrame.gcsUri" type="string">
  画像の Cloud Storage URI
</ParamField>

<ParamField body="instances[].lastFrame.mimeType" type="string">
  画像の MIME タイプ (image/jpeg または image/png)

  指定可能な値: `image/jpeg`、`image/png`
</ParamField>

<ParamField body="instances[].mask" type="object">
  ビデオ編集用のオプションのマスク。入力ビデオに適用されます。
</ParamField>

<ParamField body="instances[].mask.bytesBase64Encoded" type="string (byte)">
  Base64 でエンコードされたマスクのバイト列

  形式: `byte`
</ParamField>

<ParamField body="instances[].mask.gcsUri" type="string">
  マスクファイルの Cloud Storage URI
</ParamField>

<ParamField body="instances[].mask.maskMode" type="string">
  マスクの適用方法

  指定可能な値: `insert`、`remove`、`remove_static`、`outpaint`
</ParamField>

<ParamField body="instances[].mask.mimeType" type="string">
  マスクの MIME タイプ (image/png、image/jpeg、image/webp、またはビデオ形式)
</ParamField>

<ParamField body="instances[].prompt" type="string" required>
  生成するビデオのテキストによる説明
</ParamField>

<ParamField body="instances[].referenceImages" type="object[]">
  ビデオ生成をガイドするためのオプションの参照画像。最大 3 枚のアセット画像または 1 枚のスタイル画像をサポートします。Veo 3.1 モデル (プレビュー) でサポートされています。
</ParamField>

<ParamField body="instances[].referenceImages[].image" type="object" required />

<ParamField body="instances[].referenceImages[].image.bytesBase64Encoded" type="string (byte)">
  Base64 でエンコードされた画像データ

  形式: `byte`
</ParamField>

<ParamField body="instances[].referenceImages[].image.gcsUri" type="string">
  画像の Cloud Storage URI
</ParamField>

<ParamField body="instances[].referenceImages[].image.mimeType" type="string">
  画像の MIME タイプ (image/jpeg または image/png)

  指定可能な値: `image/jpeg`、`image/png`
</ParamField>

<ParamField body="instances[].referenceImages[].referenceId" type="string">
  参照画像の任意の識別子
</ParamField>

<ParamField body="instances[].referenceImages[].referenceType" type="string" required>
  参照画像のタイプ

  指定可能な値: `asset`、`style`
</ParamField>

<ParamField body="instances[].video" type="object">
  ビデオの拡張または編集用のオプションの入力ビデオ。image および referenceImages とは併用できません。
</ParamField>

<ParamField body="instances[].video.bytesBase64Encoded" type="string (byte)">
  Base64 でエンコードされたビデオのバイト列

  形式: `byte`
</ParamField>

<ParamField body="instances[].video.gcsUri" type="string">
  入力ビデオの Cloud Storage URI
</ParamField>

<ParamField body="instances[].video.mimeType" type="string">
  ビデオの MIME タイプ

  指定可能な値: `video/mov`、`video/mpeg`、`video/mp4`、`video/mpg`、`video/avi`、`video/wmv`、`video/mpegps`、`video/x-flv`
</ParamField>

<ParamField body="parameters" type="object" />

<ParamField body="parameters.aspectRatio" type="string">
  生成されるビデオのアスペクト比。デフォルト: 16:9

  指定可能な値: `16:9`、`9:16`
</ParamField>

<ParamField body="parameters.compressionQuality" type="string">
  ビデオの圧縮品質。デフォルト: optimized

  指定可能な値: `optimized`、`lossless`
</ParamField>

<ParamField body="parameters.durationSeconds" type="number">
  生成されるビデオの目標再生時間 (秒)。Veo 2: 5～8。Veo 3/3.1: 4、6、または 8。デフォルト: 8
</ParamField>

<ParamField body="parameters.enhancePrompt" type="boolean">
  高品質化のためにプロンプトを自動的に改善します。デフォルトは true です。
</ParamField>

<ParamField body="parameters.fps" type="integer">
  生成されるビデオのフレームレート (1 秒あたりのフレーム数)
</ParamField>

<ParamField body="parameters.generateAudio" type="boolean">
  ビデオとともにオーディオを生成するかどうか。デフォルトは true です。Veo 3.0 以降のモデルでサポートされています。
</ParamField>

<ParamField body="parameters.negativePrompt" type="string">
  生成されるビデオで避けるべき内容を記述したテキスト
</ParamField>

<ParamField body="parameters.personGeneration" type="string">
  生成されるビデオ内の人物を制御します。デフォルト: allow\_adult

  指定可能な値: `dont_allow`、`allow_adult`、`allowAll`
</ParamField>

<ParamField body="parameters.pubsubTopic" type="string">
  進捗更新用の Cloud Pub/Sub トピック (projects/\{project}/topics/\{topic})
</ParamField>

<ParamField body="parameters.resizeMode" type="string">
  入力画像のリサイズ方法。デフォルト: pad

  指定可能な値: `pad`、`crop`
</ParamField>

<ParamField body="parameters.resolution" type="string">
  出力ビデオの解像度。Veo 3.0 以降のモデルでサポートされています。デフォルト: 720p

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

<ParamField body="parameters.sampleCount" type="integer">
  生成するビデオの本数。指定しない場合は 1 本のビデオが生成されます。

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

<ParamField body="parameters.seed" type="integer">
  決定論的な出力のためのランダムシード。sampleCount > 1 の場合、ビデオごとに異なるシードが使用されます。

  形式: `uint32`
</ParamField>

<ParamField body="parameters.storageUri" type="string">
  生成されたビデオを保存するための Cloud Storage URI (gs\://)
</ParamField>

<ParamField body="parameters.task" type="string">
  ビデオ生成リクエストの操作タイプ

  指定可能な値: `textToVideo`, `imageToVideo`, `referenceToVideo`, `edit`, `extend`, `upscale`
</ParamField>

Router が `GET /v2/models/veo/veo-3.1-generate-001/openapi.json` で提供するスキーマから生成されたもので、リクエストがプロバイダーに到達する前に Router が呼び出しを検証する際に使用するドキュメントと同じです。

### 出力

<ResponseField name="done" type="boolean">
  オペレーションが完了したかどうか
</ResponseField>

<ResponseField name="error" type="object">
  エラーの詳細。オペレーションが失敗した場合に含まれます
</ResponseField>

<ResponseField name="error.code" type="integer">
  gRPC エラーコード
</ResponseField>

<ResponseField name="error.message" type="string">
  エラーメッセージ
</ResponseField>

<ResponseField name="name" type="string">
  オペレーションのリソース名
</ResponseField>

<ResponseField name="response" type="object">
  予測レスポンス。done が true の場合に含まれます
</ResponseField>

<ResponseField name="response.@type" type="string" />

<ResponseField name="response.raiMediaFilteredCount" type="integer">
  責任ある AI ポリシーによってフィルタリングされたビデオの数
</ResponseField>

<ResponseField name="response.raiMediaFilteredReasons" type="string[]">
  責任ある AI ポリシーによってビデオがフィルタリングされた理由
</ResponseField>

<ResponseField name="response.videos" type="object[]" />

<ResponseField name="response.videos[].bytesBase64Encoded" type="string">
  Base64 エンコードされたビデオコンテンツ
</ResponseField>

<ResponseField name="response.videos[].gcsUri" type="string">
  生成されたビデオの Cloud Storage URI
</ResponseField>

<ResponseField name="response.videos[].mimeType" type="string">
  ビデオの MIME タイプ (video/mp4)
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "instances": [
    {
      "prompt": "a single red maple leaf falling onto still water, slow motion"
    }
  ],
  "parameters": {
    "durationSeconds": 4,
    "generateAudio": false,
    "sampleCount": 1
  }
}
```

### 出力

```json theme={null}
{
  "done": true,
  "name": "projects/example-project/locations/us-central1/publishers/google/models/veo-3.1-fast-generate-001/operations/1a2b3c4d",
  "response": {
    "@type": "type.googleapis.com/cloud.ai.large_models.vision.GenerateVideoResponse",
    "raiMediaFilteredCount": 0,
    "videos": [
      {
        "gcsUri": "https://storage.googleapis.com/EXAMPLE_BUCKET/veo/USER_ID/REQUEST_ID/sample_0.mp4",
        "mimeType": "video/mp4"
      }
    ]
  }
}
```

## 出荷前の確認

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>
