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

# 将 Flashvsr 与 Comfy Router 配合使用

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

`wavespeed/flashvsr` 的 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 发起的同一调用。

**Model ID:** `wavespeed/flashvsr`

**Endpoint:** `POST https://api.comfy.org/v2/models/wavespeed/flashvsr`

<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/flashvsr",
              {
                  "duration": 4,
                  "target_resolution": "1080p",
                  "video": "https://samplelib.com/mp4/sample-30s.mp4",
              },
          )

      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/flashvsr", {
        duration: 4,
        target_resolution: "1080p",
        video: "https://samplelib.com/mp4/sample-30s.mp4",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/wavespeed/flashvsr \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"duration\": 4, \"target_resolution\": \"1080p\", \"video\": \"https://samplelib.com/mp4/sample-30s.mp4\"}"
      ```
    </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/flashvsr",
              {
                  "duration": 4,
                  "target_resolution": "1080p",
                  "video": "https://samplelib.com/mp4/sample-30s.mp4",
              },
          )
          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/flashvsr", {
        duration: 4,
        target_resolution: "1080p",
        video: "https://samplelib.com/mp4/sample-30s.mp4",
      });
      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/flashvsr/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"duration\": 4, \"target_resolution\": \"1080p\", \"video\": \"https://samplelib.com/mp4/sample-30s.mp4\"}"

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

## Schema

### 输入

<ParamField body="duration" type="number" required>
  视频时长，单位为秒
</ParamField>

<ParamField body="target_resolution" type="string" default="&#x22;1080p&#x22;">
  目标放大分辨率。

  可选值：`720p`、`1080p`、`2k`、`4k`
</ParamField>

<ParamField body="video" type="string" required>
  要放大的视频。可以是视频文件的 URL，也可以是 base64 编码的视频。
</ParamField>

本部分由 Router 在 `GET /v2/models/wavespeed/flashvsr/openapi.json` 提供的 schema 生成，这也是请求到达提供商之前 Router 用于校验调用的同一份文档。

### 输出

<ResponseField name="code" type="integer">
  WavespeedAI 自身的信封状态码，与 HTTP 状态码对应（本 schema 所描述的文档中为 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">
  Wavespeed 为 Router 提交并轮询的该预测分配的标识符。
</ResponseField>

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

<ResponseField name="data.outputs" type="string[]" required>
  已完成的生成结果。在 Router 返回的文档中一定存在且非空；该列表本身就是结果。每个元素都是指向已生成内容的 URL：对于 `wavespeed/flashvsr` 是 MP4，对于两个放大器是图像；或者当请求设置了 `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}
{
  "duration": 4,
  "target_resolution": "1080p",
  "video": "https://samplelib.com/mp4/sample-30s.mp4"
}
```

### 输出

```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/flashvsr/upscaled.mp4"
    ],
    "status": "completed",
    "timings": {
      "inference": 128000
    }
  },
  "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>
