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", ) ```
image | file (binary) | required | Original 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) |
model | string | required | Image model ID (e.g., `gpt-image-2.5-flare` / `gpt-image-2.5-sunburst` / `gpt-image-2` (recommended) / `gpt-image-1` / `dall-e-2`) |
prompt | string | required | Editing instruction text; more specific descriptions lead to higher generation quality (supports Chinese and English) |
mask | file (binary) | Mask image (PNG; transparent areas are editing targets). Only partially supported models support local editing mode | |
n | integer | Number of generated images | |
size | string | Image 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) | |
quality | string | Quality tier. `low/medium/high` is the native three-tier; `standard/hd` is an alias for DALL-E | |
response_format | string | Return format. `gpt-image-*` always returns `b64_json`; `url` only applies to DALL-E series | |
output_format | string | Output image encoding format (only supported by `gpt-image-*`) | |
background | string | Background type; `transparent` requires pairing with `output_format=png` or `webp` | |
user | string | Optional client-provided user identifier for upstream abuse detection |
200 — Successfully returns the edited image (including base64). usage.input_tokens_details.image_tokens reflects the visual tokens consumed by the input image (difference from text-to-image generation)400 — Request parameter error (mask size mismatch with image / unsupported image format / model does not support mask, etc.)402 — Insufficient balance# 单图图生图
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"