OpenAI GPT Image editing (i2i)

POST /v1/images/edits

Auth: {'type': 'bearer', 'description': 'Pass your API key in the `Authorization: Bearer sk-xxx` header.'}

Generate new images based on existing ones (image-to-image / image-to-image) Different from [`/v1/images/generations`](./openai-gpt-image) (text-to-image); this endpoint requires clients to provide `multipart/form-data` upload image file + text editing instruction ## Protocol highlights | Dimension | Text-to-image `/v1/images/generations` | Image-to-image `/v1/images/edits` (this endpoint) | |---|---|---| | Content-Type | `application/json` | **`multipart/form-data`** | | Required fields | `model` + `prompt` | `model` + `prompt` + **`image` (file)** | | Multiple images | — | `image[]` repeated field name (partial models support) | | Local editing | — | `mask` optional (transparent areas are editing targets) | ## Model scope Only applicable to `gpt-image-*` series (including `gpt-image-2.5-flare` / `gpt-image-2.5-sunburst`) and `dall-e-2`. Other vendors' image-to-image capabilities (e.g., Seedream / Qwen-Image-Edit) Please use the [`/v1/images/generations`](./openai-gpt-image) endpoint with JSON protocol (the upstream protocol is single endpoint designed). ## SDK example (OpenAI Python SDK) ```python from openai import OpenAI client = OpenAI(api_key="sk-xxx", base_url="https://api.router.ai/v1") # 单图基础 resp = client.images.edit( image=open("photo.png", "rb"), prompt="把背景换成赛博朋克霓虹街道", model="gpt-image-2.5-sunburst", size="1024x1024", ) # 局部编辑 (含 mask) resp = client.images.edit( image=open("portrait.png", "rb"), mask=open("mask.png", "rb"), # 蒙版透明区域 = 编辑目标 prompt="把蒙版区域替换为蓝天白云", model="gpt-image-2.5-sunburst", ) ```

Request body

imagefile (binary)requiredOriginal image file (PNG / JPEG / WebP). For a single image, the field name is `image`; for multiple reference images, repeat the field name `image[]` (partial models support multi-image input)
modelstringrequiredImage model ID (e.g., `gpt-image-2.5-flare` / `gpt-image-2.5-sunburst` / `gpt-image-2` (recommended) / `gpt-image-1` / `dall-e-2`)
promptstringrequiredEditing instruction text; more specific descriptions lead to higher generation quality (supports Chinese and English)
maskfile (binary)Mask image (PNG; transparent areas are editing targets). Only partially supported models support local editing mode
nintegerNumber of generated images
sizestringImage dimensions (width × height). The i2i endpoint (`/v1/images/edits`) **does not support 2K / 4K**, only officially supported resolutions: `gpt-image-1 / gpt-image-2 / gpt-image-2.5-*` → `1024x1024` / `1024x1536` / `1536x1024`; `dall-e-2` → `256x256` / `512x512` / `1024x1024`. For high-resolution needs (2K / 4K), please use the t2i endpoint `/v1/images/generations` (gpt-image-2 supports freeform customizations, 16 scale factor / ≤3840px / aspect ratio ≤3:1)
qualitystringQuality tier. `low/medium/high` is the native three-tier; `standard/hd` is an alias for DALL-E
response_formatstringReturn format. `gpt-image-*` always returns `b64_json`; `url` only applies to DALL-E series
output_formatstringOutput image encoding format (only supported by `gpt-image-*`)
backgroundstringBackground type; `transparent` requires pairing with `output_format=png` or `webp`
userstringOptional client-provided user identifier for upstream abuse detection

Responses

Example

# 单图图生图
curl https://api.router.ai/v1/images/edits \
  -H "Authorization: Bearer sk-xxx" \
  -F image="@photo.png" \
  -F model="gpt-image-2.5-sunburst" \
  -F prompt="把背景换成赛博朋克霓虹街道, 保留人物主体不变" \
  -F size="1024x1024" \
  -F quality="high" \
  -F n=1

# 多图参考 (部分模型支持; image[] 重复字段名上传多张)
curl https://api.router.ai/v1/images/edits \
  -H "Authorization: Bearer sk-xxx" \
  -F "image[][email protected]" \
  -F "image[][email protected]" \
  -F model="gpt-image-2.5-sunburst" \
  -F prompt="把这两张照片的主体合并到一张图里, 保留各自风格"

# 局部编辑 (mask 蒙版, 透明区域 = 编辑目标)
curl https://api.router.ai/v1/images/edits \
  -H "Authorization: Bearer sk-xxx" \
  -F image="@portrait.png" \
  -F mask="@mask.png" \
  -F model="gpt-image-2.5-sunburst" \
  -F prompt="把蒙版区域替换为蓝天白云" \
  -F size="1024x1024"

API reference