> ## 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 使用 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)中创建密钥，并将其导出为 `COMFY_API_KEY`。Python 和 TypeScript 片段使用 Comfy SDK（`pip install comfy-sdk`、`npm install @comfyorg/sdk`）；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="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(
              "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";

      // 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("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);
      ```

      ```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="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(
              "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)  # 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("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); // 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/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. 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/qwen/qwen-image-3.0-pro/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/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 在调用提供商之前就拒绝了输入。生成的资源请及时下载，因为[结果链接会过期](/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>
