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

# 图像编辑

> POST /v1/images/edits —— 基于原图与 mask 的图生图

基于原图(可附加 mask)生成编辑版本,适用于消除、扩图、风格转换等场景。

## 请求

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

### 参数

| 字段                | 类型      |  必填 | 说明                                          |
| ----------------- | ------- | :-: | ------------------------------------------- |
| `image`           | file    |  ✅  | 原图(PNG / JPEG)。`gpt-image-1` 可多张(逗号分隔或多次字段) |
| `mask`            | file    |     | 与原图同尺寸,透明区域为可编辑区                            |
| `prompt`          | string  |  ✅  | 编辑指令                                        |
| `model`           | string  |     | `gpt-image-1` / `dall-e-2`                  |
| `n`               | integer |     | 1-10                                        |
| `size`            | string  |     | `256x256` / `512x512` / `1024x1024` 等       |
| `response_format` | string  |     | `url` / `b64_json`                          |
| `quality`         | string  |     | `low` / `medium` / `high`(gpt-image-1)      |

## 响应

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

## Python 示例

```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="把背景换成沙滩",
    size="1024x1024",
    n=1,
)
print(resp.data[0].url)
```

## Mask 制作

* mask 必须与原图 **同尺寸 + PNG 透明通道**。
* **透明像素** 表示该区域允许模型重画。
* **不透明像素** 表示该区域必须保持原图。
* 可使用 Photoshop / GIMP / PIL 创建。

## 多图融合(gpt-image-1)

`gpt-image-1` 支持把多张图作为输入参考:

```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="把三个角色画到同一张海报里",
    size="1024x1024",
)
```
