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

> GPT Image image generation fields, model constraints, and request examples.

Generate images from text using the OpenAI Images request format for GPT Image models.

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

## Models

| Model ID        | Capabilities and Limits                                            |
| --------------- | ------------------------------------------------------------------ |
| `gpt-image-2`   | Generation and editing; flexible sizes; fixed high input fidelity. |
| `gpt-image-1.5` | Generation and editing; standard image sizes.                      |
| `gpt-image-1`   | Generation and editing; standard image sizes.                      |

## Request Parameters

| Field                | Type    | Required | Description                                                                                                                                                         |
| -------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`              | string  | Yes      | Complete model ID from the table above. Set it explicitly for routing.                                                                                              |
| `prompt`             | string  | Yes      | Description of the desired output or edit, at most 32000 characters.                                                                                                |
| `n`                  | integer | No       | Number of output images, 1-10; default 1.                                                                                                                           |
| `size`               | string  | No       | Output dimensions, or `auto` (default). See the model-specific size rules below.                                                                                    |
| `quality`            | string  | No       | `low`, `medium`, `high`, or `auto` (default).                                                                                                                       |
| `background`         | string  | No       | `auto` (default), `opaque`, or `transparent`. Transparency requires PNG or WebP; support on GPT Image 2 is in preview.                                              |
| `moderation`         | string  | No       | `auto` (default) or `low`, controlling the model content-filtering level.                                                                                           |
| `output_format`      | string  | No       | Encoded image format: `png` (default), `jpeg`, or `webp`.                                                                                                           |
| `output_compression` | integer | No       | Compression setting from 0 to 100, default 100. Only applies to JPEG or WebP output.                                                                                |
| `stream`             | boolean | No       | Return server-sent events when true; default false.                                                                                                                 |
| `partial_images`     | integer | No       | Streaming-only partial-image count, 0-3. With 0, the final image is sent without intermediate images; fewer partial images may arrive if generation finishes early. |
| `user`               | string  | No       | Stable identifier for the end user, used for abuse monitoring. Avoid raw personal information.                                                                      |

## Size Rules

| Model             | Allowed Sizes                                                                                                                                          |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| GPT Image 1 / 1.5 | `auto`, `1024x1024`, `1536x1024`, `1024x1536`                                                                                                          |
| GPT Image 2       | `auto` or `WIDTHxHEIGHT`. Both edges must be divisible by 16; each edge is at most 3840 px; long/short ratio at most 3:1; total pixels 655360-8294400. |

GPT Image 2 resolutions above 3686400 total pixels are experimental. These GPT models return Base64 image data; do not send DALL-E-specific `response_format` or `style`.

## Examples

Use your MixRoute key in the `MIXROUTE_API_KEY` environment variable. Requests use `Authorization: Bearer ...`. Replace source-image placeholders with accessible images or local files before editing.

```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.",
  "size": "1024x1024",
  "quality": "low",
  "n": 1,
  "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.",
  "size": "1024x1024",
  "quality": "low",
  "n": 1,
  "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"]))
```

## Response

Read each image from `data[].b64_json` and decode it using the requested `output_format`. Streaming returns partial/completed image events; use the final completed event for the final file.

[GPT Image editing](/en/api-reference/endpoint/gpt-image-edit)
