> ## 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 Editing

> Qwen Image image editing fields, model constraints, and request examples.

Edit reference images with Qwen Image using one user message containing text and image blocks.

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

## Models

| Model ID               | Input                                          |
| ---------------------- | ---------------------------------------------- |
| `qwen-image-edit`      | One text block and 1-3 reference-image blocks. |
| `qwen-image-edit-plus` | One text block and 1-3 reference-image blocks. |
| `qwen-image-edit-max`  | One text block and 1-3 reference-image blocks. |

Use [Qwen Image generation](/en/api-reference/endpoint/qwen-image) for qwen-image, qwen-image-plus, qwen-image-2.0, qwen-image-2.0-pro, and qwen-image-max.

## Request 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 plus 1-3 image blocks. Each block contains text or image, not both.                           |
| `input.messages[].content[].text`  | string  | Per content block | Prompt text in the text block.                                                                               |
| `input.messages[].content[].image` | string  | Per content block | Publicly accessible HTTPS reference-image URL, downloaded by the upstream service. Provide 1-3 image blocks. |
| `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.                                |

<Info>
  Put text and image in separate content blocks. Reference images must use public HTTPS URLs accessible to the upstream service. Use input.messages rather than input.prompt; do not send a top-level prompt, multipart files, Base64 data URIs, or a metadata wrapper.
</Info>

## Request Examples

Set `MIXROUTE_API_KEY` and replace the reference-image placeholder with a public HTTPS image 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)
```

## Response

Read image URLs from output.choices\[].message.content\[].image. usage.image\_count, usage.height, and usage.width describe the output. This response does not use the basic text-to-image output.results structure.

```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 can indicate missing reference images, an invalid model name, or an unsupported size. HTTP 429 indicates rate or concurrency limits; reduce request frequency before retrying.
