> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openp.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Image editing

> POST /v1/images/edits — image-to-image based on a source image and mask

Generate an edited version based on a source image (with an optional mask), for tasks like removal, outpainting and style transfer.

## Request

```bash theme={null}
curl https://openp.ai/v1/images/edits \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -F image="@photo.png" \
  -F mask="@mask.png" \
  -F prompt="A sunny beach in the background" \
  -F model="gpt-image-1" \
  -F size="1024x1024" \
  -F n=1
```

### Parameters

| Field             | Type    | Required | Description                                                                                    |
| ----------------- | ------- | :------: | ---------------------------------------------------------------------------------------------- |
| `image`           | file    |     ✅    | Source image (PNG / JPEG). `gpt-image-1` accepts multiple (comma-separated or repeated fields) |
| `mask`            | file    |          | Same size as the source; transparent areas are editable                                        |
| `prompt`          | string  |     ✅    | Editing instruction                                                                            |
| `model`           | string  |          | `gpt-image-1` / `dall-e-2`                                                                     |
| `n`               | integer |          | 1-10                                                                                           |
| `size`            | string  |          | `256x256` / `512x512` / `1024x1024`, etc.                                                      |
| `response_format` | string  |          | `url` / `b64_json`                                                                             |
| `quality`         | string  |          | `low` / `medium` / `high` (gpt-image-1)                                                        |

## Response

```json theme={null}
{
  "created": 1715750400,
  "data": [{"url": "https://..."}]
}
```

## Python example

```python theme={null}
from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://openp.ai/v1")

resp = client.images.edit(
    model="gpt-image-1",
    image=open("photo.png", "rb"),
    mask=open("mask.png", "rb"),
    prompt="Replace the background with a beach",
    size="1024x1024",
    n=1,
)
print(resp.data[0].url)
```

## Making a mask

* The mask must be the **same size as the source + a PNG alpha channel**.
* **Transparent pixels** mark the area the model is allowed to repaint.
* **Opaque pixels** mark the area that must stay as the original.
* You can create it with Photoshop / GIMP / PIL.

## Multi-image blending (gpt-image-1)

`gpt-image-1` supports using multiple images as input references:

```python theme={null}
resp = client.images.edit(
    model="gpt-image-1",
    image=[open("a.png","rb"), open("b.png","rb"), open("c.png","rb")],
    prompt="Draw the three characters onto a single poster",
    size="1024x1024",
)
```
