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

# 将 Ultimate Image Upscaler 与 Comfy Router 配合使用

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

`wavespeed/ultimate-image-upscaler` 的 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/ultimate-image-upscaler`

**端点：** `POST https://api.comfy.org/v2/models/wavespeed/ultimate-image-upscaler`

<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(
              "wavespeed/ultimate-image-upscaler",
              {
                  "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/ultimate-image-upscaler", {
        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/ultimate-image-upscaler \
        -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="提交排队，稍后收取">
    相同的请求体，发送至 `POST https://api.comfy.org/v2/models/wavespeed/ultimate-image-upscaler/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(
              "wavespeed/ultimate-image-upscaler",
              {
                  "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/ultimate-image-upscaler", {
        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/ultimate-image-upscaler/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/ultimate-image-upscaler/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/ultimate-image-upscaler/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### Input

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

<ParamField body="image" type="string" required>
  需要 upscale 的图像的 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/ultimate-image-upscaler/openapi.json` 提供的 schema 生成，这也是请求到达提供商之前 Router 用于校验调用的同一份文档。

### Output

<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">
  Wavespeed 为 Router 提交并轮询的预测分配的标识符。
</ResponseField>

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

<ResponseField name="data.outputs" type="string[]" required>
  已完成的生成结果。在 Router 返回的文档中存在且非空；这个列表就是结果本身。每个元素都是指向已生成内容的 URL：`wavespeed/flashvsr` 返回 MP4，两个 upscaler 返回图像；或者，对于这两个图像 id，当请求设置了 `enable_base64_output` 时，元素是 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/ultimate-image-upscaler/upscaled.png"
    ],
    "status": "completed",
    "timings": {
      "inference": 9100
    }
  },
  "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>
