> ## 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 image generation fields, model constraints, and request examples.

Qwen image generation uses two request formats depending on the model. Both call the same MixRoute endpoint; do not mix input.prompt with input.messages.

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

## Model Selection

| Models | Input Format | Image URLs |
| - | - | - |
| `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` |

For reference-image editing, use the [Qwen Image editing](/api-reference/endpoint/qwen-image-edit) page and the qwen-image-edit\* models. These request formats do not add a metadata or asset wrapper.

## Basic Text-to-Image

Use qwen-image or qwen-image-plus. The input object contains prompt, not messages.

### Parameters

| Field | Type | Required | Description |
| - | - | - | - |
| `model` | string | Yes | Complete model ID from the applicable model table. |
| `input` | object | Yes | Input object. |
| `input.prompt` | string | Yes | Text prompt. Chinese and English may be combined. Describe the desired content, style, and composition. |
| `parameters` | object | No | Optional generation settings. |
| `parameters.size` | string | No | Dimensions written as `width*height`, such as `1024*1024` or `1664*928`. Use an asterisk, not x. |
| `parameters.n` | integer | No | Only `1` is supported per request. Make separate requests for multiple images. |

### Request Examples

Set your MixRoute key in the `MIXROUTE_API_KEY` environment variable.

```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)
```

### Response

A successful result has output.task\_status="SUCCEEDED". Read temporary image URLs from output.results\[].url and save the images promptly; usage.image\_count is the actual output count.

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

## Multimodal-Format Text-to-Image

Use qwen-image-2.0, qwen-image-2.0-pro, or qwen-image-max with one user message and one text block. The request uses the multimodal envelope, but these models are listed here for text-only generation.

### Parameters

| Field | Type | Required | Description |
| - | - | - | - |
| `model` | string | Yes | Complete model ID from the applicable model table. |
| `input` | object | Yes | Input object. |
| `input.messages` | array | Yes | Exactly one user message. |
| `input.messages[].role` | string | Yes | Must be `user`. |
| `input.messages[].content` | array | Yes | One text block for text-to-image. Do not include reference images for the generation models listed here. |
| `input.messages[].content[].text` | string | Per content block | Prompt text in the text block. |
| `parameters` | object | No | Optional generation settings. |
| `parameters.size` | string | No | Dimensions written as `width*height`, such as `1024*1024` or `1664*928`. Use an asterisk, not x. |
| `parameters.n` | integer | No | Only `1` is supported per request. Make separate requests for multiple images. |
| `parameters.seed` | integer | No | Random seed. Reusing a prompt and seed can give similar results; it is not a guarantee of identical output. |
| `parameters.watermark` | boolean | No | Whether to add a watermark. |
| `parameters.negative_prompt` | string | No | Elements to avoid in the generated image. |
| `parameters.prompt_extend` | boolean | No | Whether to let the upstream service expand the prompt with additional detail. |

### Request Examples

```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)
```

### Response

Read image URLs from output.choices\[].message.content\[].image. usage.image\_count, usage.height, and usage.width describe the output. Do not parse this response with the basic interface's output.results path.

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

## Errors

HTTP 400 indicates invalid parameters, such as an empty prompt, unsupported size, or unknown model. HTTP 429 indicates rate or concurrency limits; reduce request frequency before retrying.


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