> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-chore-mintlify-theme-mint.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 通过 Comfy Router 使用 Wan 2.5 I2I Preview

> 通过 Comfy Router 调用 wan/wan2.5-i2i-preview：端点、请求结构以及 Router 返回的响应。

`wan/wan2.5-i2i-preview` 的 API 参考，由 Comfy Router 提供，来源于 Wan。

## 快速开始

在[你的 Comfy 工作区](https://platform.comfy.org/profile/api-keys?onboarding=router)中创建一个密钥，并将其导出为 `COMFY_API_KEY`。Python、TypeScript 和 Swift 片段使用 Comfy SDK（`pip install comfy-sdk`、`npm install @comfyorg/sdk`，以及 [`ComfySwiftSDK`](https://github.com/Comfy-Org/comfy-swift-sdk) Swift 包）；cURL 片段则是通过原生 HTTP 执行的同一调用。

**模型 ID：** `wan/wan2.5-i2i-preview`

**端点：** `POST https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview`

<Tabs>
  <Tab title="等待结果">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # 从环境变量中读取 COMFY_API_KEY。
      # SDK 会自动创建幂等键，并在自动重试时复用它。
      with Comfy() as client:
          result = client.models.run(
              "wan/wan2.5-i2i-preview",
              {
                  "input": {
                      "images": ["https://example.invalid/red-maple-leaf.png"],
                      "prompt": "Make the leaf golden.",
                  },
                  "parameters": {
                      "n": 1,
                      "size": "768*768",
                  },
              },
          )

      print(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // 从环境变量中读取 COMFY_API_KEY。
      // SDK 会自动创建幂等键，并在自动重试时复用它。
      const { data } = await comfy.models.run("wan/wan2.5-i2i-preview", {
        input: {
          images: ["https://example.invalid/red-maple-leaf.png"],
          prompt: "Make the leaf golden.",
        },
        parameters: {
          n: 1,
          size: "768*768",
        },
      });

      console.log(data);
      ```

      ```swift Swift theme={null}
      import Foundation
      import ComfySwiftSDK

      // 从环境变量中读取 COMFY_API_KEY。
      // SDK 每次调用都会生成一个幂等键，并在自动重试时复用它。
      let client = ComfyCloudClient(apiKey: ProcessInfo.processInfo.environment["COMFY_API_KEY"]!)
      let result = try await client.models.run(
          "wan/wan2.5-i2i-preview",
          input: [
              "input": [
                  "images": ["https://example.invalid/red-maple-leaf.png"],
                  "prompt": "Make the leaf golden.",
              ],
              "parameters": [
                  "n": 1,
                  "size": "768*768",
              ],
          ]
      )

      print(result.output)
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"images\":[\"https://example.invalid/red-maple-leaf.png\"],\"prompt\":\"Make the leaf golden.\"}, \"parameters\": {\"n\":1,\"size\":\"768*768\"}}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="加入队列并稍后收集">
    将相同的请求体发送到 `POST https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview/requests`。运行被受理后，Router 会立即返回 `201` 和 `request_id`；结果就绪后，可从本进程或其他进程收集。状态、取消与收集的完整流程见 [队列投递](/zh/development/comfy-router/queue)。

    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # 从环境中读取 COMFY_API_KEY。
      # 每次 submit() 调用都会生成自己的 Idempotency-Key，并在自动重试时复用它。
      with Comfy() as client:
          handle = client.models.submit(
              "wan/wan2.5-i2i-preview",
              {
                  "input": {
                      "images": ["https://example.invalid/red-maple-leaf.png"],
                      "prompt": "Make the leaf golden.",
                  },
                  "parameters": {
                      "n": 1,
                      "size": "768*768",
                  },
              },
          )
          print("request_id:", handle.request_id)  # 配合模型 ID，就是另一个进程所需的全部信息

          # 轮询直到请求完成，按服务器指定的 Retry-After 等待。
          for update in handle.iter_events():
              print(update.status, update.queue_position)

          # 提供商自身的载荷，与 models.run() 返回的值相同。
          # 失败或已取消的请求会在此处抛出带类型的 Router 错误。
          result = handle.get()

      print(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // 从环境中读取 COMFY_API_KEY。
      // 每次 submit() 调用都会生成自己的 Idempotency-Key，并在自动重试时复用它。
      const handle = await comfy.models.submit("wan/wan2.5-i2i-preview", {
        input: {
          images: ["https://example.invalid/red-maple-leaf.png"],
          prompt: "Make the leaf golden.",
        },
        parameters: {
          n: 1,
          size: "768*768",
        },
      });
      console.log("requestId:", handle.requestId); // 配合模型 ID，就是另一个进程所需的全部信息

      // 轮询直到请求完成，按服务器指定的 Retry-After 等待。
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // 与 models.run() 返回的结果相同。失败或已取消的请求会在此处 reject。
      const result = await handle.get();

      console.log(result.data);
      ```

      ```swift Swift theme={null}
      import Foundation
      import ComfySwiftSDK

      // 从环境中读取 COMFY_API_KEY。
      // 每次 submit() 调用都会生成自己的 Idempotency-Key，并在自动重试时复用它。
      let client = ComfyCloudClient(apiKey: ProcessInfo.processInfo.environment["COMFY_API_KEY"]!)
      let handle = try await client.models.submit(
          "wan/wan2.5-i2i-preview",
          input: [
              "input": [
                  "images": ["https://example.invalid/red-maple-leaf.png"],
                  "prompt": "Make the leaf golden.",
              ],
              "parameters": [
                  "n": 1,
                  "size": "768*768",
              ],
          ]
      )
      print("requestId:", handle.requestId)  // 配合模型 ID，就是另一个进程所需的全部信息

      // 轮询直到请求完成，按服务器指定的 Retry-After 等待。
      for try await update in handle.events() {
          print(update.state.rawValue, update.queuePosition.map(String.init) ?? "unknown")
      }

      // 提供商自身的载荷，与 models.run() 返回的值相同。
      // 失败或已取消的请求会在此处抛出带类型的 Router 错误。
      let result = try await handle.result()

      print(result.output)
      ```

      ```bash cURL theme={null}
      # 1. 提交。Router 返回 201，并附带 request_id、status_url、response_url 和 cancel_url。
      curl https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"images\":[\"https://example.invalid/red-maple-leaf.png\"],\"prompt\":\"Make the leaf golden.\"}, \"parameters\": {\"n\":1,\"size\":\"768*768\"}}"

      # 2. 轮询直到状态为 COMPLETED，按每个响应指定的 Retry-After 秒数等待。
      REQUEST_ID="<request_id from the 201 body>"
      curl -i https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview/requests/$REQUEST_ID/status \
        -H "X-API-Key: $COMFY_API_KEY"

      # 3. 收集。仍在运行时返回 202 及状态响应体，完成后返回 200 及模型的原始输出。
      curl https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### 输入

<ParamField body="input" type="object" required>
  输入基本信息，例如提示词、图像等。
</ParamField>

<ParamField body="input.images" type="string[]" required>
  用于图生图生成的图像 URL 数组
</ParamField>

<ParamField body="input.negative_prompt" type="string">
  反向提示词，用于描述你不希望在图像中出现的内容
</ParamField>

<ParamField body="input.prompt" type="string" required>
  正向提示词，用于描述期望的图像元素和视觉特征。支持中英文，长度不超过 2000 个字符
</ParamField>

<ParamField body="model" type="string">
  用于图生图生成时要调用的模型 ID。本组件不对其进行约束：Comfy Router 会从 `POST /v2/models/wan/{model}` 的 `{model}` 路径段中填充它。直接以 v1 方式调用 `POST /proxy/wan/api/v1/services/aigc/image2image/image-synthesis` 时必须提供它，可接受写法的枚举定义在该操作自身的组件 `WanImage2ImageGenerationRequest` 上。
</ParamField>

<ParamField body="parameters" type="object">
  图像处理参数
</ParamField>

<ParamField body="parameters.n" type="integer" default="4">
  生成图像的数量。范围 1-4，默认为 4

  范围：`1` 到 `4`
</ParamField>

<ParamField body="parameters.seed" type="integer">
  用于控制随机性的随机数种子。范围 \[0, 2147483647]

  范围：`0` 到 `2147483647`
</ParamField>

<ParamField body="parameters.size" type="string" default="&#x22;1280*1280&#x22;">
  输出图像分辨率，格式为 宽度*高度。默认为 1280*1280。API 接受的像素面积介于 589824（768*768）与 1638400（1280*1280）之间，宽高比介于 1:4 与 4:1 之间
</ParamField>

<ParamField body="parameters.watermark" type="boolean" default="false">
  是否在右下角添加水印标志
</ParamField>

本页内容由 Router 在 `GET /v2/models/wan/wan2.5-i2i-preview/openapi.json` 提供的 schema 生成，在请求到达提供商之前，Router 也依据同一份文档对调用进行校验。

### 输出

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

<ResponseField name="output.actual_prompt" type="string">
  智能改写后的实际提示词（用于视频任务）
</ResponseField>

<ResponseField name="output.check_audio" type="string">
  带有音频生成的 I2V 任务的音频 URL
</ResponseField>

<ResponseField name="output.code" type="string">
  失败请求的错误码（请求成功时不返回）
</ResponseField>

<ResponseField name="output.end_time" type="string">
  任务完成时间
</ResponseField>

<ResponseField name="output.message" type="string">
  失败请求的详细信息（请求成功时不返回）
</ResponseField>

<ResponseField name="output.orig_prompt" type="string">
  原始输入提示词（用于视频任务）
</ResponseField>

<ResponseField name="output.results" type="object[]">
  图像生成任务的结果列表
</ResponseField>

<ResponseField name="output.results[].actual_prompt" type="string">
  智能改写后的实际提示词（若已启用）
</ResponseField>

<ResponseField name="output.results[].code" type="string">
  图像错误码（部分任务失败时返回）
</ResponseField>

<ResponseField name="output.results[].message" type="string">
  图像错误信息（部分任务失败时返回）
</ResponseField>

<ResponseField name="output.results[].orig_prompt" type="string">
  原始输入提示词
</ResponseField>

<ResponseField name="output.results[].url" type="string">
  已生成图像的 URL 地址
</ResponseField>

<ResponseField name="output.scheduled_time" type="string">
  任务执行时间
</ResponseField>

<ResponseField name="output.submit_time" type="string">
  任务提交时间
</ResponseField>

<ResponseField name="output.task_id" type="string" required>
  任务 ID
</ResponseField>

<ResponseField name="output.task_metrics" type="object">
  图像生成任务的结果统计
</ResponseField>

<ResponseField name="output.task_metrics.FAILED" type="integer">
  失败的任务数量
</ResponseField>

<ResponseField name="output.task_metrics.SUCCEEDED" type="integer">
  成功的任务数量
</ResponseField>

<ResponseField name="output.task_metrics.TOTAL" type="integer">
  任务总数
</ResponseField>

<ResponseField name="output.task_status" type="string" required>
  任务状态

  可能的值：`PENDING`、`RUNNING`、`SUCCEEDED`、`FAILED`、`CANCELED`、`UNKNOWN`
</ResponseField>

<ResponseField name="output.video_url" type="string">
  已完成的视频生成任务的视频 URL。链接有效期 24 小时
</ResponseField>

<ResponseField name="request_id" type="string" required>
  唯一请求标识符
</ResponseField>

<ResponseField name="usage" type="object">
  输出信息统计。仅统计成功的结果
</ResponseField>

<ResponseField name="usage.SR" type="integer">
  视频分辨率等级（I2V 和 wan3.0-video 任务）
</ResponseField>

<ResponseField name="usage.duration" type="number">
  已生成视频的时长（秒）（I2V 和 wan3.0-video 任务）
</ResponseField>

<ResponseField name="usage.fps" type="integer">
  已生成视频的帧率（wan3.0-video 任务）
</ResponseField>

<ResponseField name="usage.image_count" type="integer">
  已生成图像的数量（T2I 和 I2I 任务）
</ResponseField>

<ResponseField name="usage.input_video_duration" type="number">
  输入视频的时长（秒），无视频输入时为 0.0（wan3.0-video 任务）
</ResponseField>

<ResponseField name="usage.output_video_duration" type="number">
  输出视频的时长（秒）（wan3.0-video 任务）
</ResponseField>

<ResponseField name="usage.ratio" type="string">
  已生成视频的宽高比，例如 16:9（wan3.0-video 任务）
</ResponseField>

<ResponseField name="usage.size" type="string">
  图像分辨率（T2I 和 I2I 任务）
</ResponseField>

<ResponseField name="usage.video_count" type="integer">
  已生成视频的数量（T2V 任务）
</ResponseField>

<ResponseField name="usage.video_duration" type="number">
  已生成视频的时长（秒）（T2V 任务）
</ResponseField>

<ResponseField name="usage.video_ratio" type="string">
  视频分辨率比例（T2V 任务）
</ResponseField>

<ResponseField name="code" type="string">
  失败请求的错误码，报告在响应信封的根层级而非 `output` 下（请求成功时不返回）。
</ResponseField>

<ResponseField name="message" type="string">
  失败请求的详细信息，报告在响应信封的根层级而非 `output` 下（请求成功时不返回）。在回退到 `output.message` 之前请先阅读此字段。
</ResponseField>

## 示例

### 输入

```json theme={null}
{
  "input": {
    "images": [
      "https://example.invalid/red-maple-leaf.png"
    ],
    "prompt": "Make the leaf golden."
  },
  "parameters": {
    "n": 1,
    "size": "768*768"
  }
}
```

### 输出

```json theme={null}
{
  "output": {
    "end_time": "2027-01-01T00:00:12.000Z",
    "results": [
      {
        "actual_prompt": "a single red maple leaf resting on still water, shallow depth of field, soft morning light",
        "orig_prompt": "a single red maple leaf resting on still water",
        "url": "https://example.invalid/wan/generated-1.png"
      },
      {
        "code": "DataInspectionFailed",
        "message": "This candidate was rejected; the task as a whole succeeded.",
        "orig_prompt": "a single red maple leaf resting on still water"
      }
    ],
    "scheduled_time": "2027-01-01T00:00:01.000Z",
    "submit_time": "2027-01-01T00:00:00.000Z",
    "task_id": "0385dc79-5ff8-4d82-bcb6-7c1a9f2e4d60",
    "task_metrics": {
      "FAILED": 1,
      "SUCCEEDED": 1,
      "TOTAL": 2
    },
    "task_status": "SUCCEEDED"
  },
  "request_id": "7574ee8f-38a3-4b1e-9280-11c33ab46e51",
  "usage": {
    "image_count": 1,
    "size": "1280*1280"
  }
}
```

## 发布前须知

SDK 会生成 `Idempotency-Key` 并在自动重试中复用它。手动重试时，请复用原始 key。Router 最长可保持连接 10 分钟。

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

上文任何字段描述中提到的尺寸限制，都是提供商对该字段自身的限定，引自提供商的规范。Router 会对整个请求体另行设置上限，base64 编码的媒体内容也计入其中：参见[请求体大小](/zh/development/comfy-router/limitations)。

本页记录的是通过 Comfy Router 调用的某一个合作伙伴模型。同一个 `comfy-sdk` / `@comfyorg/sdk` 包还提供第二个客户端，用于在 Comfy Cloud 上运行完整的 ComfyUI 工作流图：`Comfy(api_key=...)` / `new Comfy({ apiKey })`，并带有 `client.workflows`、`client.assets` 和 `client.jobs`。请参阅 [Comfy SDKs](/zh/development/api-development/sdks)。

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

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

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