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

# GPT Image 2

> GPT Image 2: 画像生成モデル。MixRouteでのリクエスト例とパラメータ。

GPT Image 2は、以下で説明するネイティブ画像APIを通じて利用できます。

画像の生成と編集に対応しています。サイズの制約、透明な背景への対応、入力忠実度はモデルによって異なります。

<Tip>
  [生成パラメーター](/ja/api-reference/endpoint/gpt-image) | [編集パラメーター](/ja/api-reference/endpoint/gpt-image-edit)
</Tip>

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

## 例

環境変数`MIXROUTE_API_KEY`にMixRouteのキーを設定してください。リクエストは`Authorization: Bearer ...`を使用します。編集前に、元画像のプレースホルダーをアクセス可能な画像またはローカルファイルに置き換えてください。

```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": "gpt-image-2",
  "prompt": "A clean product photograph of a red ceramic mug on a white background.",
  "n": 1,
  "size": "1024x1024",
  "quality": "low",
  "output_format": "png"
}'
```

### Python

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

payload = json.loads(r'''
{
  "model": "gpt-image-2",
  "prompt": "A clean product photograph of a red ceramic mug on a white background.",
  "n": 1,
  "size": "1024x1024",
  "quality": "low",
  "output_format": "png"
}
''')
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()
import base64
from pathlib import Path

for index, item in enumerate(result["data"]):
    Path(f"image_{index}.png").write_bytes(base64.b64decode(item["b64_json"]))
```


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