> ## 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 使用 Qwen Image 3.0 Pro

> 通过 Comfy Router 调用 qwen/qwen-image-3.0-pro：端点、请求格式以及 Router 返回的响应。

`qwen/qwen-image-3.0-pro` 的 API 参考文档，由 Comfy Router 从 Qwen 提供服务。

## 快速开始

在[你的 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：** `qwen/qwen-image-3.0-pro`

**端点：** `POST https://api.comfy.org/v2/models/qwen/qwen-image-3.0-pro`

<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(
              "qwen/qwen-image-3.0-pro",
              {
                  "input": {
                      "messages": [
                          {
                              "content": [
                                  {
                                      "text": "A single red maple leaf on a plain white background.",
                                  },
                              ],
                              "role": "user",
                          },
                      ],
                  },
              },
          )

      print(result)
      ```

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

      // 从环境变量读取 COMFY_API_KEY。
      // SDK 会自动创建一个幂等键，并在自动重试时复用它。
      const { data } = await comfy.models.run("qwen/qwen-image-3.0-pro", {
        input: {
          messages: [
            {
              content: [
                {
                  text: "A single red maple leaf on a plain white background.",
                },
              ],
              role: "user",
            },
          ],
        },
      });

      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(
          "qwen/qwen-image-3.0-pro",
          input: [
              "input": [
                  "messages": [
                      [
                          "content": [
                              [
                                  "text": "A single red maple leaf on a plain white background.",
                              ],
                          ],
                          "role": "user",
                      ],
                  ],
              ],
          ]
      )

      print(result.output)
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/qwen/qwen-image-3.0-pro \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"messages\":[{\"content\":[{\"text\":\"A single red maple leaf on a plain white background.\"}],\"role\":\"user\"}]}}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="入队并稍后收集">
    将相同的请求体发送到 `POST https://api.comfy.org/v2/models/qwen/qwen-image-3.0-pro/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(
              "qwen/qwen-image-3.0-pro",
              {
                  "input": {
                      "messages": [
                          {
                              "content": [
                                  {
                                      "text": "A single red maple leaf on a plain white background.",
                                  },
                              ],
                              "role": "user",
                          },
                      ],
                  },
              },
          )
          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("qwen/qwen-image-3.0-pro", {
        input: {
          messages: [
            {
              content: [
                {
                  text: "A single red maple leaf on a plain white background.",
                },
              ],
              role: "user",
            },
          ],
        },
      });
      console.log("requestId:", handle.requestId); // 配合模型 ID，就是另一个进程所需的全部信息

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

      // 与 models.run() 返回的结果相同。失败或已取消的请求会在此处被拒绝。
      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(
          "qwen/qwen-image-3.0-pro",
          input: [
              "input": [
                  "messages": [
                      [
                          "content": [
                              [
                                  "text": "A single red maple leaf on a plain white background.",
                              ],
                          ],
                          "role": "user",
                      ],
                  ],
              ],
          ]
      )
      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/qwen/qwen-image-3.0-pro/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"messages\":[{\"content\":[{\"text\":\"A single red maple leaf on a plain white background.\"}],\"role\":\"user\"}]}}"

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

      # 3. 收集。返回 200 表示返回模型的原生输出，返回 202 表示任务仍在运行、返回的是状态响应体。
      curl https://api.comfy.org/v2/models/qwen/qwen-image-3.0-pro/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### 输入

<ParamField body="input" type="object" required>
  包含请求消息的输入参数对象
</ParamField>

<ParamField body="input.messages" type="object[]" required>
  请求内容数组。仅支持单轮对话，因此该数组必须恰好包含一个对象
</ParamField>

<ParamField body="input.messages[].content" type="object[]" required>
  消息内容数组。文生图包含一个 text 对象；图像编辑包含 1-3 个 image 对象和一个 text 对象
</ParamField>

<ParamField body="input.messages[].content[].image" type="string">
  输入图像的 URL 或 Base64 编码数据。图像编辑支持 1-3 张图像
</ParamField>

<ParamField body="input.messages[].content[].text" type="string">
  描述要生成或编辑的图像内容、风格和构图的正面提示词
</ParamField>

<ParamField body="input.messages[].role" type="string" required>
  消息发送者的角色。必须设置为 user

  可选值：`user`
</ParamField>

<ParamField body="model" type="string">
  用于多模态图像生成与编辑的模型 ID。可选值为 qwen-image-3.0-pro 和 qwen-image-3.0。它不在本 schema 的 `required` 列表中，因为 Comfy Router 会从 /v2/models/qwen/\{model} 的 `{model}` 路径段中填充它，所以 Router 调用方会省略该字段；而直接以 v1 调用 /proxy/ 路由时必须提供它。
</ParamField>

<ParamField body="parameters" type="object">
  用于控制图像生成的附加参数
</ParamField>

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

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

<ParamField body="parameters.negative_prompt" type="string">
  描述你不希望出现在图像中的内容的负面提示词
</ParamField>

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

<ParamField body="parameters.prompt_extend_mode" type="string" default="&#x22;direct&#x22;">
  提示词改写方法，direct（默认，支持 T2I 和 I2I）或 agent（仅支持 T2I）

  可选值：`direct`、`agent`
</ParamField>

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

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

<ParamField body="parameters.size" type="string">
  输出图像分辨率，格式为 宽*高，例如 1024*1024。API 接受的像素面积介于 262144 (512*512) 与 6553600 (2560*2560) 之间，宽高比介于 1:8 与 8:1 之间。若未指定，模型会根据提示词自动推荐分辨率
</ParamField>

<ParamField body="parameters.watermark" type="boolean" default="false">
  是否添加水印。默认为 false
</ParamField>

本文档根据 Router 在 `GET /v2/models/qwen/qwen-image-3.0-pro/openapi.json` 提供的 schema 生成，该 schema 也是请求到达提供商之前 Router 校验调用时所依据的同一份文档。

### 输出

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

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

<ResponseField name="output" type="object">
  包含模型生成结果
</ResponseField>

<ResponseField name="output.choices" type="object[]">
  结果选项列表
</ResponseField>

<ResponseField name="output.choices[].finish_reason" type="string">
  任务停止的原因。任务正常完成时该值为 stop
</ResponseField>

<ResponseField name="output.choices[].message" type="object">
  模型返回的消息
</ResponseField>

<ResponseField name="output.choices[].message.content" type="object[]">
  包含已生成图像信息的消息内容
</ResponseField>

<ResponseField name="output.choices[].message.content[].image" type="string">
  已生成图像的 URL，格式为 PNG。该链接有效期为 24 小时
</ResponseField>

<ResponseField name="output.choices[].message.content[].text" type="string">
  代替图像返回的文本元素。仅带有此字段的元素不会产出任何资源，因此调用方应依据 `image` 而非内容元素是否存在来判断是否完成
</ResponseField>

<ResponseField name="output.choices[].message.role" type="string">
  消息的角色。固定为 assistant
</ResponseField>

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

<ResponseField name="usage" type="object">
  本次调用的资源使用情况。仅在成功时返回
</ResponseField>

<ResponseField name="usage.input_image_count" type="integer">
  请求中的输入图像数量。文生图返回 0
</ResponseField>

<ResponseField name="usage.input_image_type" type="string">
  输入图像计费档位，qima\_input\_1k 或 qima\_input\_2k，由输出分辨率的像素面积决定
</ResponseField>

<ResponseField name="usage.output_height" type="integer">
  最终输出图像的高度（像素）
</ResponseField>

<ResponseField name="usage.output_image_count" type="integer">
  实际返回的输出图像数量
</ResponseField>

<ResponseField name="usage.output_image_type" type="string">
  输出图像计费档位，qima\_output\_1k 或 qima\_output\_2k，由输出分辨率的像素面积决定
</ResponseField>

<ResponseField name="usage.output_width" type="integer">
  最终输出图像的宽度（像素）
</ResponseField>

## 示例

### 输入

```json theme={null}
{
  "input": {
    "messages": [
      {
        "content": [
          {
            "text": "A single red maple leaf on a plain white background."
          }
        ],
        "role": "user"
      }
    ]
  }
}
```

### 输出

```json theme={null}
{
  "output": {
    "choices": [
      {
        "finish_reason": "stop",
        "message": {
          "content": [
            {
              "image": "https://example.invalid/qwen/generated.png"
            }
          ],
          "role": "assistant"
        }
      }
    ]
  },
  "request_id": "9f2c1b3a-5d4e-4a67-8b90-1c2d3e4f5a6b",
  "usage": {
    "input_image_count": 0,
    "output_height": 512,
    "output_image_count": 1,
    "output_image_type": "qima_output_1k",
    "output_width": 512
  }
}
```

## 发布前须知

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>
