Skip to main content
POST
Image editing: edit an existing image per instructions
The interactive Playground on the right supports dropdown selection for parameters. Enter your API Key in the Authorization field (format: Bearer sk-xxx) to send test requests with one click.
Scope: This page is for image editing. You must provide an input image (base64-encoded) along with edit instructions. To generate a new image from text only, use the Text-to-Image endpoint.
🖥️ Browser Playground limitation (important)This endpoint returns a base64-encoded image (inlineData.data, 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 (less than 50KB) to shrink the response.
⚠️ parts array structure (important — read this for multi-image edits)Each part must be either a text or an inlineData, never both. This matches Google’s official gemini-3.1-flash-lite-image contract.Correct: one text part (the instruction) + N inlineData parts (one per image):
Incorrect (each part contains both text and inlineData — produces undefined behavior):
🖼️ About the inlineData.data fieldThis endpoint uses JSON format (not multipart file upload), so the Playground cannot directly select local files. You need to convert your image to a Base64 string first, then paste it into the data input.One-line command: convert + copy to clipboard:
After running, just Cmd+V / Ctrl+V paste into the data field in the Playground. Also remember to set mimeType to the matching image/jpeg or image/png.Recommendation: Use small images (less than 200KB) for testing to avoid browser lag from long base64 strings. For frequent image editing tests, use the code examples below to run locally instead.

Code Examples

Python

Node.js

cURL

Multi-Image Editing

When merging or comparing several input images, use a single text part (the instruction) followed by multiple inlineData parts (one per image).

Python (multi-image)

Parameter Quick Reference

Multi-turn conversational editing

Nano Banana 2 Lite (gemini-3.1-flash-lite-image) supports conversational multi-turn editing: append each turn’s generated image back into contents as a role: "model" inlineData, then send the next user instruction. The model edits based on the full conversation history and accumulates changes (e.g. first recolor the sofa, then add an accessory — the earlier change is preserved).
Start multi-turn from an existing image: put an inlineData (your own image) plus an instruction in the first user message to edit an existing photo, then keep backfilling the model output into contents each turn.

Authorizations

Authorization
string
header
required

API Key obtained from the APIYI console

Body

application/json
contents
object[]
required

Content array containing the edit instruction and the image(s) to edit

generationConfig
object
required

Response

Image generated successfully

candidates
object[]

Array of generation results

usageMetadata
object