> ## Documentation Index
> Fetch the complete documentation index at: https://comfyuiwiki.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 Qwen Image 3.0 搭配 Comfy Router

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

`qwen/qwen-image-3.0` 的 API 参考，该模型由 Comfy Router 提供，来自 Qwen。

## 快速开始

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

**模型 ID：** `qwen/qwen-image-3.0`

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

<Tabs defaultTabIndex={1}>
  <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",
              {
                  "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", {
        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 \
        -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/requests`。运行被受理后，Router 会立即返回 `201` 和 `request_id`；结果就绪后，可以从本进程或其他进程收集。状态、取消与收集的细节见[队列投递](/zh/development/comfy-router/queue)。

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

      # 从环境变量中读取 COMFY_API_KEY。
      # 每次 submit() 调用都会生成自己的 Idempotency-Key，并在自动重试时复用它。
      async def main():
          async with AsyncComfy() as client:
              handle = await client.models.submit(
                  "qwen/qwen-image-3.0",
                  {
                      "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。
              async for update in handle.iter_events():
                  print(update.status, update.queue_position)

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

          print(result)

      asyncio.run(main())
      ```

      ```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", {
        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);
      ```

      ```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/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/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/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 个图像对象和一个 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 调用方会省略它；而直接向 /proxy/ 路由发起的 v1 调用则必须提供它。
</ParamField>

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

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

  Range: `1` to `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]

  Range: `0` to `2147483647`
</ParamField>

<ParamField body="parameters.size" type="string">
  输出图像分辨率，格式为 width*height，例如 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/openapi.json` 提供的 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>
