> ## 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の画像編集フィールド、モデルの制約、リクエスト例。

テキストと画像ブロックを含む1つのユーザーメッセージを使用して、Qwen Imageで参照画像を編集します。

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

## モデル

| モデルID | 入力 |
| - | - |
| `qwen-image-edit` | テキストブロック1つと参照画像ブロック1〜3つ。 |
| `qwen-image-edit-plus` | テキストブロック1つと参照画像ブロック1〜3つ。 |
| `qwen-image-edit-max` | テキストブロック1つと参照画像ブロック1〜3つ。 |

qwen-image、qwen-image-plus、qwen-image-2.0、qwen-image-2.0-pro、qwen-image-maxには、[Qwen Imageによる画像生成](/ja/api-reference/endpoint/qwen-image)を使用してください。

## リクエストパラメーター

| フィールド | 型 | 必須 | 説明 |
| - | - | - | - |
| `model` | string | はい | 該当するモデル表に記載された完全なモデルID。 |
| `input` | object | はい | 入力オブジェクト。 |
| `input.messages` | array | はい | ユーザーメッセージは必ず1つです。 |
| `input.messages[].role` | string | はい | `user`である必要があります。 |
| `input.messages[].content` | array | はい | テキストブロック1つと画像ブロック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`のように、`width*height`形式で記述した寸法。xではなくアスタリスクを使用してください。 |
| `parameters.n` | integer | いいえ | 1回のリクエストでサポートされるのは`1`のみです。複数の画像には、個別のリクエストを送信してください。 |
| `parameters.seed` | integer | いいえ | 乱数シード。同じプロンプトとシードを再利用すると似た結果が得られる場合がありますが、同一の出力を保証するものではありません。 |
| `parameters.watermark` | boolean | いいえ | ウォーターマークを追加するかどうか。 |
| `parameters.negative_prompt` | string | いいえ | 生成画像で避ける要素。 |
| `parameters.prompt_extend` | boolean | いいえ | 上流サービスにプロンプトの詳細を補足させるかどうか。 |

<Info>
  テキストと画像は別々のcontentブロックに配置してください。参照画像には、上流サービスからアクセスできる公開HTTPS URLを使用する必要があります。input.promptではなくinput.messagesを使用してください。トップレベルのprompt、multipartファイル、Base64データ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)
```

## レスポンス

画像URLはoutput.choices\[].message.content\[].imageから取得します。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.