Image editing. Both the official OpenAI SDK's multipart/form-data upload and a
JSON body (base64 string) are accepted.
Body
modelstringYes- ID of a model that supports editing
promptstringYes- 1–4000 characters
imagestring | fileYes- Source image — a base64 string in JSON, a file part in multipart
maskstring | fileNo- Mask for the region to edit. Check
capabilities.image_mask nintegerNo- Number of images to generate, 1–4 (default 1)
sizestringNo256x256·512x512·1024x1024·1792x1024·1024x1792·1536x1024·1024x1536·auto. Only values supported by the selected model are accepted; omission uses the model defaultresponse_formatstringNourl(default) ·b64_jsonuserstringNo- End-user identifier
The entire multipart body is limited to 4 MiB; JSON is limited to 5 MiB.
After file-to-base64 conversion, the payload must also fit within 5 MiB. Exceeding these limits returns
413 request_too_large or invalid_request_error. Check encoded byte size, not only image dimensions.
Model-specific editing
Choose a model with capabilities.image_editing: true in GET /v1/models. capabilities.image_mask describes mask support. Omitted fields mean unverified support; unsupported options return 400.
- Native Gemini image supports prompt-based editing without a mask. Explicit
maskreturns 400 and is never ignored. Onlyn: 1is supported. Size aliases have the same aspect-ratio/resolution meaning as image generation. - Imagen editing rejects explicit
sizewith 400. Regular edits preserve the source size; upscale uses a 2× factor. - Omitting
sizeuses the model default; no shared1024x1024default is injected. Checklimits.supported_sizesandlimits.max_images, subject to the generation/editing differences documented here.