> ## 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 调用 Wan 2.5 I2V Preview

> 通过 Comfy Router 以 HTTP 调用 wan/wan2.5-i2v-preview 的 Python、TypeScript 和 cURL 代码片段，以及请求字段和结果结构

Wan 2.5 I2V 预览的 API 参考。Wan 2.5 图生视频可将一张静态首帧图像转换为一段短视频，其中的运动与相机运镜由提示词描述。

## 快速开始

在[你的 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：** `wan/wan2.5-i2v-preview`

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

<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(
              "wan/wan2.5-i2v-preview",
              {
                  "input": {
                      "prompt": "the robot lowers its raised arm and steps toward the camera, the flat orange backdrop holds steady",
                      "img_url": "https://raw.githubusercontent.com/Comfy-Org/workflow_templates/main/input/pink_robot_front.png",
                  },
                  "parameters": {
                      "resolution": "720P",
                      "duration": 5,
                  },
              },
          )

      print("video:", result["output"]["video_url"])
      ```

      ```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.
      type Result = { output: { video_url: string } };
      const { data } = await comfy.models.run<Result>("wan/wan2.5-i2v-preview", {
        input: {
          prompt: "the robot lowers its raised arm and steps toward the camera, the flat orange backdrop holds steady",
          img_url: "https://raw.githubusercontent.com/Comfy-Org/workflow_templates/main/input/pink_robot_front.png",
        },
        parameters: {
          resolution: "720P",
          duration: 5,
        },
      });

      console.log("video:", data.output.video_url);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/wan/wan2.5-i2v-preview \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"prompt\":\"the robot lowers its raised arm and steps toward the camera, the flat orange backdrop holds steady\",\"img_url\":\"https://raw.githubusercontent.com/Comfy-Org/workflow_templates/main/input/pink_robot_front.png\"}, \"parameters\": {\"resolution\":\"720P\",\"duration\":5}}"
      ```
    </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(
              "wan/wan2.5-i2v-preview",
              {
                  "input": {
                      "prompt": "the robot lowers its raised arm and steps toward the camera, the flat orange backdrop holds steady",
                      "img_url": "https://raw.githubusercontent.com/Comfy-Org/workflow_templates/main/input/pink_robot_front.png",
                  },
                  "parameters": {
                      "resolution": "720P",
                      "duration": 5,
                  },
              },
          )
          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("video:", result["output"]["video_url"])
      ```

      ```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.
      type Result = { output: { video_url: string } };
      const handle = await comfy.models.submit<Result>("wan/wan2.5-i2v-preview", {
        input: {
          prompt: "the robot lowers its raised arm and steps toward the camera, the flat orange backdrop holds steady",
          img_url: "https://raw.githubusercontent.com/Comfy-Org/workflow_templates/main/input/pink_robot_front.png",
        },
        parameters: {
          resolution: "720P",
          duration: 5,
        },
      });
      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();
      if (result.kind !== "json") throw new Error("expected a JSON result");

      console.log("video:", result.data.output.video_url);
      ```

      ```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/wan/wan2.5-i2v-preview/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"prompt\":\"the robot lowers its raised arm and steps toward the camera, the flat orange backdrop holds steady\",\"img_url\":\"https://raw.githubusercontent.com/Comfy-Org/workflow_templates/main/input/pink_robot_front.png\"}, \"parameters\": {\"resolution\":\"720P\",\"duration\":5}}"

      # 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/wan/wan2.5-i2v-preview/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/wan/wan2.5-i2v-preview/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## 数据结构

### 输入

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

<ParamField body="input.audio_url" type="string">
  音频文件下载网址。支持的格式：mp3 和 wav。不能与 reference\_video\_urls 一起使用。
</ParamField>

<ParamField body="input.img_url" type="string">
  首帧图片网址或 Base64 编码数据。I2V 模型必填。图片格式：JPEG、JPG、PNG、BMP、WEBP。分辨率：360-2000 像素。文件大小：最大 10MB。
</ParamField>

<ParamField body="input.media" type="object[]">
  用于 wan2.7 和 wan3.0 模型的媒体资产列表。指定用于视频生成的参考素材（图像、音频、视频）。
  每个元素包含一个 type 字段和一个 url 字段。
  支持的 type 取值因模型而异：

  * wan2.7-i2v：first\_frame、last\_frame、driving\_audio、first\_clip
  * wan2.7-r2v：reference\_image、reference\_video
  * wan2.7-videoedit：video、reference\_image
  * wan3.0-video：first\_frame（最大 1 个）、last\_frame（最大 1 个）、reference\_image（最大 10 个）、
    reference\_video（最大 5 段，总时长 \<= 15s）、reference\_audio（最大 5 段，
    总时长 \<= 15s）、file（最大 1 个，不能与 link 一起使用）、link（最大 1 个，不能
    与 file 一起使用）。reference\_\*/file/link 类型与 first\_frame/last\_frame 类型
    在同一请求中互斥。数组顺序决定了提示词中资产的引用
    顺序（Image 1、Video 1、Audio 1……）。
</ParamField>

<ParamField body="input.media[].type" type="string" required>
  媒体资产类型

  可能的值：`first_frame`、`last_frame`、`driving_audio`、`first_clip`、`reference_image`、`reference_video`、`reference_audio`、`video`、`file`、`link`
</ParamField>

<ParamField body="input.media[].url" type="string" required>
  媒体文件的网址（公开的 HTTP/HTTPS 网址或 OSS 临时网址）
</ParamField>

<ParamField body="input.negative_prompt" type="string">
  反向提示词用于描述你不希望在视频画面中看到的内容
</ParamField>

<ParamField body="input.prompt" type="string">
  文本提示词。支持中文和英文，长度不超过 800 个字符
  （wan3.0-video 最多 20,000 个字符；超出限制的内容会被截断）。
  对于带有多个参考视频的 wan2.6-r2v，请按参考视频的顺序使用 'character1'、'character2' 等
  来指代主体。示例："Character1 在路边唱歌，Character2 在旁边跳舞"。
  对于 wan3.0-video 参考模式，请使用 'Image 1'、'Video 1'、'Audio 1' 等来指代
  media 数组中对应顺序的媒体资产。
</ParamField>

<ParamField body="input.reference_video_urls" type="string[]">
  仅用于 wan2.6-r2v 模型的参考视频网址。由 1-3 个视频网址组成的数组。
  输入限制：

  * 格式：mp4、mov
  * 数量：1-3 个视频
  * 单个视频长度：2-30 秒
  * 单个文件大小：最大 30MB
  * 不能与 audio\_url 一起使用
    参考时长：单个视频最大 5s，两个视频每个最大 2.5s，三个视频按比例减少。
    计费：按实际使用的参考时长计算。
</ParamField>

<ParamField body="input.template" type="string">
  视频效果模板名称。可选。目前支持：squish、flying、carousel。使用时，prompt 参数会被忽略。
</ParamField>

<ParamField body="model" type="string">
  要调用的模型 ID。此组件不做约束：Comfy Router 会从 `POST /v2/models/wan/{model}` 的 `{model}` 路径段中填入它，因此 Router 调用方可省略该字段。直接以 v1 方式调用 `POST /proxy/wan/api/v1/services/aigc/video-generation/video-synthesis` 时必须提供该字段，可接受拼写的枚举定义在该操作自有的组件 `WanVideoGenerationRequest` 上。
</ParamField>

<ParamField body="parameters" type="object">
  视频处理参数
</ParamField>

<ParamField body="parameters.audio" type="boolean" default="true">
  是否为视频添加音频
</ParamField>

<ParamField body="parameters.audio_setting" type="string" default="&#x22;auto&#x22;">
  wan2.7-videoedit 模型的视频音频设置。

  * auto（默认）：模型根据提示词内容智能判断
  * origin：强制保留输入视频的原始音频

    可能的值：`auto`、`origin`
</ParamField>

<ParamField body="parameters.duration" type="integer" default="5">
  生成视频的时长，单位为秒：

  * wan2.5 模型：5 或 10 秒
  * wan2.6-t2v、wan2.6-i2v：5、10 或 15 秒
  * wan2.6-r2v：仅 5 或 10 秒（不支持 15s）
  * wan2.7-i2v、wan2.7-t2v：\[2, 15] 范围内的整数
  * wan2.7-r2v、wan2.7-videoedit：\[2, 10] 范围内的整数
  * wan3.0-video：无视频输入时为 \[2, 30] 范围内的整数；有视频输入时，
    输入视频总时长 + 输出视频时长不得超过 30 秒；-1 启用
    智能时长模式，由模型选择合适的时长

    范围：`-1` 到 `30`
</ParamField>

<ParamField body="parameters.prompt_extend" type="boolean" default="true">
  是否启用提示词智能改写。默认为 true
</ParamField>

<ParamField body="parameters.ratio" type="string">
  生成视频的比例。仅适用于 wan2.7 和 wan3.0 模型。
  对于 wan2.7 模型，如果未提供，则根据分辨率档位使用默认值。
  对于 wan3.0-video，adaptive（默认）会根据输入媒体的
  比例和意图自动推荐合适的比例。

  可能的值：`adaptive`、`16:9`、`9:16`、`1:1`、`4:3`、`3:4`
</ParamField>

<ParamField body="parameters.resolution" type="string">
  分辨率级别。支持的取值因模型而异：

  * wan2.5-i2v-preview：480P、720P、1080P
  * wan2.6-i2v：仅 720P、1080P（不支持 480P）
  * wan2.7 模型（i2v、t2v、r2v、videoedit）：720P、1080P（默认 1080P）
  * wan3.0-video、wan3.0-video-prime：480P、720P、1080P（上游默认 1080P）
    此代理会拒绝既未提供 resolution 也未提供 size 的视频生成请求，
    因为分辨率档位决定了计费标准。

    可能的值：`480P`、`720P`、`1080P`
</ParamField>

<ParamField body="parameters.seed" type="integer">
  随机数种子，用于控制模型生成内容的随机性

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

<ParamField body="parameters.shot_type" type="string" default="&#x22;single&#x22;">
  智能多镜头控制。仅在启用 prompt\_extend 时生效。
  适用于 wan2.6 和 wan2.7-r2v 模型。

  * single：单镜头视频（默认）
  * multi：多镜头视频

    可能的值：`multi`、`single`
</ParamField>

<ParamField body="parameters.size" type="string">
  视频分辨率，格式为 宽度*高度。支持的尺寸因模型而异：
  wan2.5 T2V：480P（480*832、832*480、624*624）、720P、1080P 尺寸
  wan2.6 T2V/R2V（无 480P）：
  720P：1280*720、720*1280、960*960、1088*832、832*1088
  1080P：1920*1080、1080*1920、1440*1440、1632*1248、1248*1632
</ParamField>

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

由 Router 在 `GET /v2/models/wan/wan2.5-i2v-preview/openapi.json` 提供的 schema 生成，这也是请求到达提供商之前用于校验调用的同一份文档。

### 输出

<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">
  已生成图像的图片网址
</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": {
    "prompt": "the robot lowers its raised arm and steps toward the camera, the flat orange backdrop holds steady",
    "img_url": "https://raw.githubusercontent.com/Comfy-Org/workflow_templates/main/input/pink_robot_front.png"
  },
  "parameters": {
    "resolution": "720P",
    "duration": 5
  }
}
```

### 输出

```json theme={null}
{
  "output": {
    "task_id": "0385dc79-5ff8-4d82-bcb6-7c1a9f2e4d60",
    "task_status": "SUCCEEDED",
    "submit_time": "2027-01-01T00:00:00.000Z",
    "scheduled_time": "2027-01-01T00:00:01.000Z",
    "end_time": "2027-01-01T00:01:04.000Z",
    "orig_prompt": "the robot lowers its raised arm and steps toward the camera, the flat orange backdrop holds steady",
    "actual_prompt": "the robot lowers its raised arm and steps toward the camera, the flat orange backdrop holds steady, smooth studio lighting, subtle camera push in",
    "video_url": "https://.../generated.mp4"
  },
  "request_id": "7574ee8f-38a3-4b1e-9280-11c33ab46e51",
  "usage": {
    "SR": 720,
    "duration": 5
  }
}
```

视频 URL 的有效期为 24 小时。如需保留该视频，请及时下载。

## 发布前须知

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>
