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

# Qwen Image 编辑

> Qwen Image 图片编辑字段、模型限制与请求示例。

通过包含文本块与图片块的单条 user 消息，使用 Qwen Image 编辑参考图片。

`POST https://api.mixroute.ai/v1/images/generations`

## 支持模型

| 模型 ID                  | 输入                 |
| ---------------------- | ------------------ |
| `qwen-image-edit`      | 一个文本块及 1-3 个参考图片块。 |
| `qwen-image-edit-plus` | 一个文本块及 1-3 个参考图片块。 |
| `qwen-image-edit-max`  | 一个文本块及 1-3 个参考图片块。 |

qwen-image、qwen-image-plus、qwen-image-2.0、qwen-image-2.0-pro、qwen-image-max 的生成请求见 [Qwen Image](/cn/api-reference/endpoint/qwen-image)。

## 请求参数

| 字段                                 | 类型      | 必填   | 说明                                                   |
| ---------------------------------- | ------- | ---- | ---------------------------------------------------- |
| `model`                            | string  | 是    | 对应模型表中的完整模型 ID。                                      |
| `input`                            | object  | 是    | 输入对象。                                                |
| `input.messages`                   | array   | 是    | 有且只有一条 user 消息。                                      |
| `input.messages[].role`            | string  | 是    | 固定为 `user`。                                          |
| `input.messages[].content`         | array   | 是    | 包含一个文本块及 1-3 个图片块，每个块只使用 text 或 image，不能同时包含两者。      |
| `input.messages[].content[].text`  | string  | 按内容块 | 文本块中的提示词。                                            |
| `input.messages[].content[].image` | string  | 按内容块 | 参考图片的公网 HTTPS URL，由上游服务下载；请求包含 1-3 个图片块。             |
| `parameters`                       | object  | 否    | 可选生成设置。                                              |
| `parameters.size`                  | string  | 否    | 尺寸采用 `宽*高` 格式，例如 `1024*1024` 或 `1664*928`，使用星号而不是 x。 |
| `parameters.n`                     | integer | 否    | 单次请求仅支持 `1` 张；需要多张时分别调用。                             |
| `parameters.seed`                  | integer | 否    | 随机种子。同提示词和同种子可产生近似结果，不保证完全相同。                        |
| `parameters.watermark`             | boolean | 否    | 是否添加水印。                                              |
| `parameters.negative_prompt`       | string  | 否    | 希望图片中避免出现的元素。                                        |
| `parameters.prompt_extend`         | boolean | 否    | 是否由上游服务扩展提示词、补充细节。                                   |

<Info>
  text 和 image 必须分别放在不同内容块中。参考图使用上游可访问的公网 HTTPS URL。请求采用 input.messages 而不是 input.prompt；不传顶层 prompt、multipart 文件、Base64 data URI 或 metadata 包装。
</Info>

## 请求示例

设置 `MIXROUTE_API_KEY`，并将参考图占位值替换为公网 HTTPS 图片 URL。

```bash theme={null}
curl --request POST "https://api.mixroute.ai/v1/images/generations" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "qwen-image-edit",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "text": "Change the mug to blue while preserving the background."
          },
          {
            "image": "https://example.com/reference.png"
          }
        ]
      }
    ]
  },
  "parameters": {
    "size": "1024*1024",
    "n": 1,
    "seed": 42
  }
}'
```

### Python

```python theme={null}
import json
import os
import requests

payload = json.loads(r'''
{
  "model": "qwen-image-edit",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "text": "Change the mug to blue while preserving the background."
          },
          {
            "image": "https://example.com/reference.png"
          }
        ]
      }
    ]
  },
  "parameters": {
    "size": "1024*1024",
    "n": 1,
    "seed": 42
  }
}
''')
response = requests.post(
    "https://api.mixroute.ai/v1/images/generations",
    headers={"Authorization": "Bearer " + os.environ["MIXROUTE_API_KEY"]},
    json=payload,
    timeout=180,
)
response.raise_for_status()
result = response.json()
output = result.get("output") or {}
image_urls = [
    part["image"]
    for choice in output.get("choices", [])
    for part in choice.get("message", {}).get("content", [])
    if part.get("image")
]
if not image_urls:
    raise RuntimeError(result.get("message") or result)
for url in image_urls:
    print(url)
```

## 响应

从 output.choices\[].message.content\[].image 读取图片 URL。usage.image\_count、usage.height、usage.width 描述生成结果，不使用基础文生图的 output.results 结构。

```json theme={null}
{
  "output": {
    "choices": [
      {
        "message": {
          "role": "assistant",
          "content": [
            {
              "image": "https://example.com/generated.png"
            }
          ]
        }
      }
    ]
  },
  "usage": {
    "image_count": 1,
    "height": 1024,
    "width": 1024
  }
}
```

## 错误处理

HTTP 400 可能表示缺少参考图、模型名称无效或尺寸不支持。HTTP 429 表示频次或并发超限，应降低调用频率后重试。
