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

# 将 Seedvr 2 与 Comfy Router 配合使用

> 通过 Comfy Router 调用 wavespeed/seedvr2：端点、请求形状以及 Router 返回的响应。

`wavespeed/seedvr2` 的 API 参考文档，由 Comfy Router 提供，来自 WaveSpeed。

## 快速开始

在 [你的 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：** `wavespeed/seedvr2`

**端点：** `POST https://api.comfy.org/v2/models/wavespeed/seedvr2`

<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(
              "wavespeed/seedvr2",
              {
                  "image": "https://images.pexels.com/photos/346529/pexels-photo-346529.jpeg",
                  "target_resolution": "4k",
              },
          )

      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("wavespeed/seedvr2", {
        image: "https://images.pexels.com/photos/346529/pexels-photo-346529.jpeg",
        target_resolution: "4k",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/wavespeed/seedvr2 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"image\": \"https://images.pexels.com/photos/346529/pexels-photo-346529.jpeg\", \"target_resolution\": \"4k\"}"
      ```
    </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(
              "wavespeed/seedvr2",
              {
                  "image": "https://images.pexels.com/photos/346529/pexels-photo-346529.jpeg",
                  "target_resolution": "4k",
              },
          )
          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("wavespeed/seedvr2", {
        image: "https://images.pexels.com/photos/346529/pexels-photo-346529.jpeg",
        target_resolution: "4k",
      });
      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/wavespeed/seedvr2/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"image\": \"https://images.pexels.com/photos/346529/pexels-photo-346529.jpeg\", \"target_resolution\": \"4k\"}"

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

## 模式

### 输入

<ParamField body="enable_base64_output" type="boolean" default="false">
  如果启用，输出将被编码为 BASE64 字符串，而不是 URL。
</ParamField>

<ParamField body="image" type="string" required>
  要放大的图像的 URL。
</ParamField>

<ParamField body="output_format" type="string" default="&#x22;jpeg&#x22;">
  输出图像的格式。

  可选值：`jpeg`、`png`、`webp`
</ParamField>

<ParamField body="target_resolution" type="string" default="&#x22;4k&#x22;">
  输出图像的目标分辨率。

  可选值：`2k`、`4k`、`8k`
</ParamField>

该模式由 Router 在 `GET /v2/models/wavespeed/seedvr2/openapi.json` 提供的 schema 生成，也是请求到达提供商之前 Router 用于校验调用所依据的同一份文档。

### 输出

<ResponseField name="code" type="integer">
  WavespeedAI 自身的信封状态码，与 HTTP 状态对应（在本文档所描述的响应中为 200）。Wavespeed 的部分失败会在此处报告，而不是在传输层状态中报告。
</ResponseField>

<ResponseField name="data" type="object" required />

<ResponseField name="data.created_at" type="string">
  Wavespeed 创建该预测时的 ISO-8601 时间戳。
</ResponseField>

<ResponseField name="data.error" type="string">
  Wavespeed 的自由文本失败原因，没有失败时为空字符串。真正失败的预测会以 Comfy Router 错误的形式返回给 Router 调用方，而不是以本文档的形式返回。
</ResponseField>

<ResponseField name="data.id" type="string">
  Router 提交并轮询的预测在 Wavespeed 侧的标识符。
</ResponseField>

<ResponseField name="data.model" type="string">
  该预测运行所使用的 Wavespeed 模型 id。
</ResponseField>

<ResponseField name="data.outputs" type="string[]" required>
  已完成的生成结果。在 Router 返回的文档中必定存在且非空；这个列表本身就是结果。每个元素都是指向生成内容的 URL：`wavespeed/flashvsr` 为 MP4，两个 upscaler 为图像；或者，当请求设置了 `enable_base64_output` 时，两个图像 id 的元素就是 base64 编码的字节本身。这些链接由 Wavespeed 提供，会过期。
</ResponseField>

<ResponseField name="data.status" type="string" required>
  该预测的终端状态，按 Wavespeed 的写法书写。此处不限定为枚举：Router 会原样转发该值，而轮询分类器在比较之前会将其转为小写，因此成功状态可以合理地以 `completed`、`succeeded`、`success` 或 `done` 到达，且不区分大小写。
</ResponseField>

<ResponseField name="data.timings" type="object">
  Wavespeed 自身的计时测量值。
</ResponseField>

<ResponseField name="data.timings.inference" type="integer">
  推理时间，单位为毫秒。这是 Wavespeed 的数值，不是 Comfy 的计费。
</ResponseField>

<ResponseField name="data.urls" type="object">
  Wavespeed 自身针对该预测的链接。
</ResponseField>

<ResponseField name="data.urls.get" type="string">
  Router 所轮询的预测结果 URL。
</ResponseField>

<ResponseField name="message" type="string">
  信封状态消息，例如 `success`。
</ResponseField>

## 示例

### 输入

```json theme={null}
{
  "image": "https://images.pexels.com/photos/346529/pexels-photo-346529.jpeg",
  "target_resolution": "4k"
}
```

### 输出

```json theme={null}
{
  "code": 200,
  "data": {
    "created_at": "2027-01-01T00:00:00Z",
    "error": "",
    "id": "3f6c1a90-2b47-4d18-9a55-7c0e8b21d4f3",
    "outputs": [
      "https://example.invalid/wavespeed/seedvr2/upscaled.png"
    ],
    "status": "completed",
    "timings": {
      "inference": 4200
    }
  },
  "message": "success"
}
```

## 发布前须知

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>
