> ## 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の画像生成では、モデルに応じて2種類のリクエスト形式を使用します。どちらも同じ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編集](/ja/api-reference/endpoint/qwen-image-edit)ページとqwen-image-edit\*モデルを使用してください。これらのリクエスト形式には、metadataやassetのラッパーを追加しません。

## 基本的なテキストから画像への生成

qwen-imageまたはqwen-image-plusを使用します。inputオブジェクトにはmessagesではなくpromptを含めます。

### パラメータ

| フィールド | 型 | 必須 | 説明 |
| - | - | - | - |
| `model` | string | はい | 該当するモデル表に記載された完全なモデルID。 |
| `input` | object | はい | 入力オブジェクト。 |
| `input.prompt` | string | はい | テキストプロンプトです。中国語と英語を混在させることができます。希望する内容、スタイル、構図を記述してください。 |
| `parameters` | object | いいえ | 任意の生成設定。 |
| `parameters.size` | string | いいえ | `1024*1024`や`1664*928`のように、`width*height`形式で記述した寸法。xではなくアスタリスクを使用してください。 |
| `parameters.n` | integer | いいえ | 1回のリクエストでサポートされるのは`1`のみです。複数の画像には、個別のリクエストを送信してください。 |

### リクエスト例

`MIXROUTE_API_KEY`環境変数にMixRouteのキーを設定してください。

```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から一時的な画像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のいずれかを、1つのユーザーメッセージと1つのテキストブロックで使用してください。リクエストはマルチモーダルの構造を使用しますが、ここではこれらのモデルをテキストのみを入力とする生成用として掲載しています。

### パラメータ

| フィールド | 型 | 必須 | 説明 |
| - | - | - | - |
| `model` | string | はい | 該当するモデル表に記載された完全なモデルID。 |
| `input` | object | はい | 入力オブジェクト。 |
| `input.messages` | array | はい | ユーザーメッセージは必ず1つです。 |
| `input.messages[].role` | string | はい | `user`である必要があります。 |
| `input.messages[].content` | array | はい | テキストから画像を生成するためのテキストブロック1つ。ここに掲載されている生成モデルには、参照画像を含めないでください。 |
| `input.messages[].content[].text` | string | コンテンツブロックごと | テキストブロック内のプロンプトテキスト。 |
| `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 | いいえ | 上流サービスにプロンプトの詳細を補足させるかどうか。 |

### リクエスト例

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

### レスポンス

画像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.