> ## 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 2.0 Generate 001

> 通过 Comfy Router 调用 veo/veo-2.0-generate-001：端点、请求结构以及 Router 返回的响应。

`veo/veo-2.0-generate-001` 的 API 参考文档，由 Comfy Router 提供，来源于 Veo。

<h2 id="quick-start">
  快速开始
</h2>

在[你的 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-2.0-generate-001`

**端点：** `POST https://api.comfy.org/v2/models/veo/veo-2.0-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-2.0-generate-001",
              {
                  "instances": [
                      {
                          "prompt": "a single red maple leaf falling onto still water, slow motion",
                      },
                  ],
                  "parameters": {
                      "durationSeconds": 6,
                      "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-2.0-generate-001", {
        instances: [
          {
            prompt: "a single red maple leaf falling onto still water, slow motion",
          },
        ],
        parameters: {
          durationSeconds: 6,
          sampleCount: 1,
        },
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/veo/veo-2.0-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\":6,\"sampleCount\":1}}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="排队并稍后收集">
    相同的请求体，发送到 `POST https://api.comfy.org/v2/models/veo/veo-2.0-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-2.0-generate-001",
              {
                  "instances": [
                      {
                          "prompt": "a single red maple leaf falling onto still water, slow motion",
                      },
                  ],
                  "parameters": {
                      "durationSeconds": 6,
                      "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-2.0-generate-001", {
        instances: [
          {
            prompt: "a single red maple leaf falling onto still water, slow motion",
          },
        ],
        parameters: {
          durationSeconds: 6,
          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-2.0-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\":6,\"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-2.0-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-2.0-generate-001/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### 输入

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

<ParamField body="instances[].image" type="object">
  用于引导视频生成的可选图像
</ParamField>

<ParamField body="instances[].image.bytesBase64Encoded" type="string (byte)">
  格式：`byte`
</ParamField>

<ParamField body="instances[].image.gcsUri" type="string" />

<ParamField body="instances[].image.mimeType" type="string" />

<ParamField body="instances[].prompt" type="string" required>
  视频的文本描述
</ParamField>

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

<ParamField body="parameters.aspectRatio" type="string" />

<ParamField body="parameters.durationSeconds" type="integer" />

<ParamField body="parameters.enhancePrompt" type="boolean" />

<ParamField body="parameters.negativePrompt" type="string" />

<ParamField body="parameters.personGeneration" type="string">
  控制已生成视频中的人物。`dont_allow`、`allow_adult` 和 `allowAll` 是 Vertex AI 自身的拼写，也是 VeoGenVidRequest 为同一字段发布的取值。`ALLOW` 和 `BLOCK` 是为了兼容在此组件由 Router 编写之前基于它生成的客户端而保留的，详见 Veo2GenVidRequest 顶部的说明。

  可能的值：`ALLOW`、`BLOCK`、`dont_allow`、`allow_adult`、`allowAll`
</ParamField>

<ParamField body="parameters.sampleCount" type="integer" />

<ParamField body="parameters.seed" type="integer">
  格式：`uint32`
</ParamField>

<ParamField body="parameters.storageUri" type="string">
  用于上传视频的可选 Cloud Storage URI
</ParamField>

根据 Router 在 `GET /v2/models/veo/veo-2.0-generate-001/openapi.json` 提供的 schema 生成，这也是它在请求到达提供商之前用于校验调用的同一份文档。

### 输出

<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">
  被 Responsible AI 策略过滤的视频数量
</ResponseField>

<ResponseField name="response.raiMediaFilteredReasons" type="string[]">
  视频被 Responsible 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": 6,
    "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>
