> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-chore-sync-comfy-api-v2-spec.mintlify.site/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 参考，由 Comfy Router 从 Veo 提供。

## 快速开始

在[你的 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`，结果就绪后即可从当前进程或另一个进程收集。[队列投递](/zh/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>

<h2 id="schema">
  Schema
</h2>

<h3 id="input">
  输入
</h3>

<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">
  自动优化提示词以获得更高质量。默认为是。
</ParamField>

<ParamField body="parameters.fps" type="integer">
  生成视频的帧率，单位为每秒帧数
</ParamField>

<ParamField body="parameters.generateAudio" type="boolean">
  是否随视频一起生成音频。默认为是。由 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` 提供，同样也是请求到达提供商之前用于校验调用的文档。

### 输出

<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 为是时存在
</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` 并在自动重试中复用它。手动重试时，请复用原始 key。Router 最长可保持连接 10 分钟。

请求失败时，Router 会发送 `X-Comfy-Error-Type` 响应头说明原因。`422` 表示 Router 在调用提供商之前就拒绝了输入。生成的资源请及时下载，因为[结果链接会过期](/zh/development/comfy-router/reference#结果资产)。

<CardGroup cols={3}>
  <Card title="请求头" icon="list" href="/zh/development/comfy-router/quickstart">
    身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。
  </Card>

  <Card title="使用 Router API" icon="code" href="/zh/development/comfy-router/quickstart">
    模型发现、校验错误、重试与计费。
  </Card>

  <Card title="限制" icon="triangle-exclamation" href="/zh/development/comfy-router/limitations">
    Router 目前不支持的功能，以及替代方案。
  </Card>
</CardGroup>
