> ## 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 图片生成字段、模型限制与请求示例。

Qwen 图片生成按模型使用两种请求格式，均调用同一个 MixRoute 端点。不要混用 input.prompt 与 input.messages。

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

## 模型选择

| 模型 | 输入格式 | 图片 URL 位置 |
| - | - | - |
| `qwen-image`, `qwen-image-plus` | `input.prompt` | `output.results[].url` |
| `qwen-image-2.0`, `qwen-image-2.0-pro`, `qwen-image-max` | `input.messages` | `output.choices[].message.content[].image` |

参考图编辑请使用 [Qwen Image 编辑](/zh-hans/api-reference/endpoint/qwen-image-edit) 页面中的 qwen-image-edit\* 模型。请求不增加 metadata 或 asset 包装。

## 基础文生图

使用 qwen-image 或 qwen-image-plus。input 对象中传入 prompt，而不是 messages。

### 参数

| 字段 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `model` | string | 是 | 对应模型表中的完整模型 ID。 |
| `input` | object | 是 | 输入对象。 |
| `input.prompt` | string | 是 | 文本提示词，支持中英文混合，可描述内容、风格与构图。 |
| `parameters` | object | 否 | 可选生成设置。 |
| `parameters.size` | string | 否 | 尺寸采用 `宽*高` 格式，例如 `1024*1024` 或 `1664*928`，使用星号而不是 x。 |
| `parameters.n` | integer | 否 | 单次请求仅支持 `1` 张；需要多张时分别调用。 |

### 请求示例

将 MixRoute Key 设置为环境变量 `MIXROUTE_API_KEY`。

```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-plus",
  "input": {
    "prompt": "A clean product photograph of a red ceramic mug on a white background."
  },
  "parameters": {
    "size": "1024*1024",
    "n": 1
  }
}'
```

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

payload = json.loads(r'''
{
  "model": "qwen-image-plus",
  "input": {
    "prompt": "A clean product photograph of a red ceramic mug on a white background."
  },
  "parameters": {
    "size": "1024*1024",
    "n": 1
  }
}
''')
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 {}
if output.get("task_status") != "SUCCEEDED":
    raise RuntimeError(result.get("message") or result)
image_urls = [item["url"] for item in output.get("results", []) if item.get("url")]
if not image_urls:
    raise RuntimeError(result.get("message") or result)
for url in image_urls:
    print(url)
```

### 响应

成功结果的 output.task\_status 为 "SUCCEEDED"。从 output.results\[].url 读取临时图片地址并及时保存；usage.image\_count 表示实际生成张数。

```json theme={null}
{
  "output": {
    "task_status": "SUCCEEDED",
    "results": [
      {
        "url": "https://example.com/generated.png"
      }
    ]
  },
  "usage": {
    "image_count": 1
  }
}
```

## 多模态格式文生图

qwen-image-2.0、qwen-image-2.0-pro、qwen-image-max 使用一条 user 消息和一个文本块。请求采用多模态结构，本页将这些型号列为纯文生图模型。

### 参数

| 字段 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `model` | string | 是 | 对应模型表中的完整模型 ID。 |
| `input` | object | 是 | 输入对象。 |
| `input.messages` | array | 是 | 有且只有一条 user 消息。 |
| `input.messages[].role` | string | 是 | 固定为 `user`。 |
| `input.messages[].content` | array | 是 | 文生图包含一个文本块。本页列出的生成模型不传参考图。 |
| `input.messages[].content[].text` | string | 按内容块 | 文本块中的提示词。 |
| `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 | 否 | 是否由上游服务扩展提示词、补充细节。 |

### 请求示例

```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-2.0-pro",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "text": "A clean product photograph of a red ceramic mug on a white background."
          }
        ]
      }
    ]
  },
  "parameters": {
    "size": "1024*1024",
    "n": 1,
    "seed": 42
  }
}'
```

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

payload = json.loads(r'''
{
  "model": "qwen-image-2.0-pro",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "text": "A clean product photograph of a red ceramic mug on a white background."
          }
        ]
      }
    ]
  },
  "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 表示频次或并发超限，应降低调用频率后重试。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.