Skip to main content
POST
Image Edit: edit or fuse reference images by instruction
The interactive Playground on the right supports direct local image upload. Fill in your API Key in Authorization (format: Bearer sk-xxx), select image / mask files, fill in prompt and model, and send.
Use case: This page is for “edit / fuse / inpaint based on one or more reference images”. Request format is multipart/form-data. For pure text-to-image, use the Text-to-Image endpoint.
🖥️ Browser Playground limitation (important)This endpoint returns a raw base64 string (typically several MB) in the response. Due to browser rendering limits, the Playground on the right may show 请求时发生错误: unable to complete request after the response arrives — the request actually succeeded; the browser just can’t render such a long base64 string.Recommended workflow (beginner-friendly):
  • Copy the Python / Node.js / cURL sample below and run it locally. The code automatically base64.b64decodes the response and writes the image to a file.
  • If you must use the in-browser Playground, use a tiny reference image (< 50KB), set size to the smallest tier (e.g. 1024x1024), and quality to low.
⚠️ Key differences (when migrating from gpt-image-1.5)
  • Do not pass input_fidelitygpt-image-2 forces high-fidelity; passing it returns 400
  • Edit requests have noticeably higher input tokens — references convert to many tokens via Vision pricing; budget accordingly
  • background: transparent not supported — use opaque or post-process
  • Multi-image fusion: max 16 — repeat the image[] field; more than 16 errors out
📎 Multi-image fusion order mattersThe image[] field accepts multiple reference images. Upload order maps to “image 1 / image 2 / image 3” references in the prompt. Reference them explicitly:
Place subject from image 1 into scene from image 2, using color style from image 3
Per-file limit: under 50MB each (multipart file upload), formats: png / jpg / webp; in practice compress to within 1.5MB before uploading (see “Upload Size Limits” below).

Code Examples

Python (OpenAI SDK · single-image edit)

Python (OpenAI SDK · multi-image fusion)

cURL (multi-image fusion)

cURL (mask inpainting)

Node.js (Native fetch + FormData · multi-image fusion)

Parameter Reference

Do not pass the legacy DALL·E values standard / hd for quality. Only the four official enum values low / medium / high / auto are accepted. The legacy values behave inconsistently across backend channels: sometimes they fail immediately with a 400 (invalid_value), and sometimes they are silently ignored and the request runs at auto (unpredictable cost). Always pass one of the four official values explicitly.

Upload Size Limits

Don’t max out the total request size: even though the per-image cap is 50MB with up to 16 images, multiple near-cap images make a single request body enormous and prone to gateway / CDN / timeout failures. In practice, compress each image to within 1.5MB (JPEG quality 80-90) — success rate and generation speed both improve noticeably, and output quality is unrelated to input file size.

Reference Image Format Requirements and Preprocessing

/v1/images/edits only accepts png / jpg / webp standard formats. If you receive this 400:
the reference image is most likely not a standard JPEG/PNG. The most common trap is MPO format (Multi-Picture Object, a multi-frame JPEG container) from phone cameras: .jpg files straight out of Huawei Mate-series phones embed an HDR gain-map sub-frame and are actually MPO. These files start with the same FFD8 header — the extension and the file command both report JPEG — so they’re impossible to spot by eye; only frame-aware parsing (e.g. Pillow) can tell. The “image 1” in the error refers to the Nth reference image (1-indexed), so use the index to locate the offending file.
Verified July 2026: MPO files failed with 400 on 5/5 uploads; the same images re-encoded as standard JPEG/PNG succeeded at the full original 3072×4096 resolution — the problem is the format, not the dimensions or file size. The error is returned quickly (~4s) at the input-validation stage and is not billed.
Detection and fix: if Image.open(f).format returns "MPO", the file needs conversion. A single re-encode step in your upload pipeline also covers HEIC and other phone formats:
If your product accepts user-shot photos (interior renders, product shots, etc.), re-encode uniformly on the server side rather than debugging images one by one — phone HDR photos will keep showing up. More input-handling tips: Image API Essentials and Best Practices.

Mask Inpainting Requirements

  • Same size as original, PNG format, under 4MB
  • Must have alpha channel: transparent (alpha=0) = inpaint area, opaque = preserve
  • Mask only applies to the first image
  • Mask is a “soft guide” — the model may extend or contract around the masked region
Multi-turn iteration: feed the previous output back as the next call’s image[] with a new instruction to incrementally refine. Each round is independently token-billed — watch cumulative cost.

Response Format

b64_json is raw base64, without the data:image/...;base64, prefix — different from gpt-image-2-all. Decode it client-side to write a file, or prepend the prefix for browser rendering.
Edit requests’ input_tokens are typically significantly higher than text-to-image at the same size, because reference images are billed per Vision pricing rules — the exact amount is available directly in usage.input_tokens_details.image_tokens, tracked separately from the text portion (text_tokens). Multi-image fusion increases image_tokens strictly linearly per additional reference image (verified July 2026: 4 × 1024² images = 4 × 1024 tokens) — see How Multiple Input Images Affect the Price for the measurement table. See How to check the real token count for each call on the overview page for the full field reference.

Authorizations

Authorization
string
header
required

API Key obtained from APIYI Console

Body

multipart/form-data
model
enum<string>
default:gpt-image-2
required

Model name, fixed as gpt-image-2

Available options:
gpt-image-2
prompt
string
required

Edit/fusion instruction. For multi-image, use 'image 1 / image 2 / image 3' to reference upload order

Example:

"Place subject from image 1 into scene from image 2, using color style from image 3"

image
file[]
required

Reference images. For a single image, send the field once; for multiple images, repeat the same image field (e.g., -F image=@a.png -F image=@b.png, max 16) — upload order maps to image 1 / image 2 / ... in the prompt. multipart file upload: each under 50MB, formats: png/jpg/webp; compress to within 1.5MB in practice

mask
file

Mask image (optional, only applies to first image). Requirements:

  • Same size as original
  • PNG format, under 4MB
  • Must have alpha channel (alpha=0 = inpaint area, opaque = preserve)
size
string
default:auto

Output size (same as text-to-image). Preset or constraint-satisfying custom size

Example:

"1536x1024"

quality
enum<string>
default:auto

Quality tier

Available options:
auto,
low,
medium,
high
output_format
enum<string>
default:png

Output format

Available options:
png,
jpeg,
webp
output_compression
integer

Output compression (0–100), only effective for jpeg/webp

Required range: 0 <= x <= 100
background
enum<string>
default:auto

Background mode. auto or opaque. Not supported: transparent

Available options:
auto,
opaque

Response

Image generated successfully

created
integer
Example:

1776832476

data
object[]

Generation results (this model returns 1 image per call)

usage
object

Token usage for this call