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

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

Edit one or more images with GPT Image using the OpenAI Images editing request format.

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

## 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.                                                                                                                           |
| `image`              | file \| file\[] | Yes      | PNG, JPEG, or WebP inputs, each under 50 MB, up to 16 images. Upload files as multipart form data; repeat `image[]` for multiple files.                                                        |
| `mask`               | file            | No       | PNG mask under 4 MB with the same pixel dimensions as the first source image. Fully transparent pixels identify the region to edit; a multi-image request applies the mask to its first image. |
| `input_fidelity`     | string          | No       | `high` or `low` for GPT Image 1 and 1.5. Omit this field for GPT Image 2, which always processes image inputs at high fidelity.                                                                |
| `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.                                                                         |
| `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`.

<Info>
  Use multipart/form-data, not a JSON image URL object. Let cURL or the SDK set the multipart boundary. `input_fidelity=auto/medium` and a top-level `images` JSON array are not fields of this OpenAI request.
</Info>

## 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/edits" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --form "model=gpt-image-2" \
  --form "image[]=@source.png" \
  --form "prompt=Make the mug blue while preserving its shape, lighting, and background." \
  --form "size=1024x1024" \
  --form "quality=low" \
  --form "output_format=png"
```

### Python

```python theme={null}
import os
import base64
from pathlib import Path
from openai import OpenAI

client = OpenAI(api_key=os.environ["MIXROUTE_API_KEY"], base_url="https://api.mixroute.ai/v1")
with open("source.png", "rb") as source:
    result = client.images.edit(
        model="gpt-image-2",
        image=source,
        prompt="Make the mug blue while preserving its shape, lighting, and background.",
        size="1024x1024",
        quality="low",
        output_format="png",
    )
Path("edited.png").write_bytes(base64.b64decode(result.data[0].b64_json))
```

For masked editing, add the `mask` file. For multiple references, provide additional image files; a mask still applies only to the first.

## 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 generation](/en/api-reference/endpoint/gpt-image)
