gemini-3-pro-image) can change a detail, restyle a photo, or compose several images into a new one from a text instruction. This guide covers both request formats on LaoZhang API; each edit costs one fixed per-call price at any size.
To create images from text alone, see Nano Banana Pro image generation.
Before you start
1
Create an API key
In Token management, open the create-token dialog (创建令牌), set Billing mode (计费模式) to Usage first (按量优先, recommended) or Per-call (按次计费), and click Create (创建). Nano Banana Pro has only a per-call price, and a Usage-based (按量计费) key can’t call it; the billing rules explain when a request is charged.

2
Set the key and install the dependencies
3
Add a save function for cURL
The cURL examples need When the response holds no image, the function prints the error,
jq. Define this shell function to save the last image in a Gemini-native response, which is the final result if interim images come back too, with the extension that matches its mimeType:promptFeedback, and finishReason fields instead.Edit a local image
Send the request toPOST https://api.laozhang.ai/v1beta/models/gemini-3-pro-image:generateContent. Put the instruction first and the images after it in parts. Each local file goes in as an inlineData part whose mimeType matches the file.
- Python
- cURL
Save this script as Add a hat to a cat photo at 2K:
nano_banana_pro_edit.py. It sends the instruction with 1 to 14 local images and saves every image in the response:aspectRatio, so the result keeps Google’s default of matching the input image’s size. Add aspectRatio (or --ratio) to change the shape; the pixel dimensions for each ratio and size are listed under Output sizes. A 4K edit takes longer than a 1K edit, so keep a generous client timeout; the examples allow 300 seconds.
Combine reference images
List up to 14 files after the instruction, in the order you refer to them, and name each image’s role in the prompt:- 6 object images that must appear in the result with high fidelity, such as products or props
- 5 character images that keep people consistent across a series
- 3 style images that set the look, such as a palette or brushwork
Edit an image from a public URL
The Gemini-native route can also take an image by URL through afileData part instead of Base64:
fileUri with the public HTTPS address of your image and set mimeType to match it. The image is fetched from that address during the request, so it must load without a login, cookies, or bot checks. If it can’t be fetched, download the file and send it as inlineData instead.
- Use a URL once the request would pass 20 MB. Keep the whole request body under 20 MB; images sent as
inlineDatashould total about 15 MB or less, so pass larger ones infileDataor downscale them first. - The site’s
robots.txtmust not block crawlers from the image’s path, and a signed URL should stay valid for at least 30 minutes to cover queueing and retries. fileDataandinlineDataparts can share onepartsarray, in reference order. The full conditions are in Large images and image URLs.
Use the OpenAI-compatible route
If your app already uses the OpenAI SDK, send edits through chat completions. Put the instruction and the images in one user message asimage_url parts: a local file as a data URL, or a public HTTPS URL.
This route has no ratio or size settings; use the Gemini-native route for 2K, 4K, or a fixed ratio. The image comes back as a Base64 data URL inside message.content. Save this script as nano_banana_pro_chat_edit.py:
Handle the response
- Gemini-native: each image is an
inlineDatapart incandidates[].content.parts[], withmimeTypeand Base64data.- Skip any part marked
thought: true. Pro thinks before it renders, and a complex edit can return interim images along with the result; the last image is the final one. - Save the file with the extension that matches
mimeType.
- Skip any part marked
- Chat completions: the image is a data URL such as
data:image/png;base64,...inside the text ofchoices[0].message.content. Take the format from the prefix, strip the prefix, and add=padding before decoding if the length isn’t a multiple of 4. - No image: check each candidate’s
finishReason, andpromptFeedbackif present, in native responses, or the reply text in chat responses. Common reasons are a safety block or an instruction the model answered with text only.
Prompt tips for edits
- Say what must stay unchanged, such as a face, a product label, or the layout. There is no mask parameter, so describe the area to change in words.
- Refer to each image by its order and role, such as “the jacket in the second image”.
- To keep a face or a logo intact, describe it in detail and say that it must not change.
- For text inside the image, put the exact words in quotes and name the font style.
- Split a complex edit into steps, and send each saved result as the input of the next request.
Errors and billing
Send values that Pro accepts:- A request can return HTTP 200 without an image, for example when a safety check blocks the output. Edits are billed like generations, so the call is charged. Check
finishReason(andpromptFeedbackif present), then change the instruction or reference images before resending; see Avoid paying for empty responses. - HTTP 401 means the key or the
Authorization: Bearerheader is wrong; the Gemini-native route also accepts the key inx-goog-api-key. Retry 429 and 5xx responses with backoff, and check call logs before resending a request that timed out. - If a
fileDataURL can’t be fetched, check that it loads without a login and thatrobots.txtallows it, or send the image asinlineDatainstead. - HTTP 413 means the request body is too large. Pass large images by URL, or downscale them so the whole request stays under 20 MB.
- Base64 makes a file about a third larger, so downscale very large photos before you encode them.
FAQ
Can I edit with /v1/images/edits?
No. Nano Banana Pro edits go through the Gemini-native generateContent endpoint or OpenAI-compatible /v1/chat/completions, not the Images API edit endpoint.
Can I edit only one area of an image?
Yes, by describing it; there is no mask field. Google calls this semantic masking: name the element to change and say that everything else must stay the same, for example “Change only the blue sofa to a brown leather sofa. Keep the rest of the room, the layout, and the lighting unchanged.” See Prompt tips for edits for more.What shape is the result when I leave out aspectRatio?
Google’s default is to match the output to the input image’s size, so leaving out aspectRatio keeps the original shape; the examples in Edit a local image work this way. Set aspectRatio only when you want a different shape, and keep imageSize to choose 1K, 2K, or 4K.
Related pages and sources
- Nano Banana Pro image generation — text-to-image, output sizes by ratio, and Google Search grounding
- Nano Banana 2 — lower-cost generation and editing up to 4K
- Nano Banana overview — compare the five models, the two request formats, and billing rules
- Nano Banana image editing (Standard) — edits with
gemini-2.5-flash-imageand its migration path - Call logs — check a request’s status and charge
- Google: Nano Banana image generation — editing prompts, reference limits, and thinking
- Google: generateContent reference —
imageConfigfields - Google: file input methods — inline data and public URL inputs