Nano Banana 2 API guide: fast image generation
Call Nano Banana 2 (gemini-3.1-flash-image) through DreamTo: generateContent requests, 1K to 4K sizes, 14 aspect ratios, reference images, limits and price.

On this page
Nano Banana 2 is Google's Gemini 3.1 Flash Image, the Flash-tier Nano Banana model. On DreamTo its model ID is gemini-3.1-flash-image, and one generateContent request takes a prompt, optional reference images, a size of 1K, 2K or 4K, and and one of 14 aspect ratios, including extreme ones such as 1:8 and 8:1, and returns the image. This guide covers the request, every parameter the docs list, reference images, the parameters that return 400 and what a request costs.
One thing to know before you build on it: our catalog notes that Google now recommends Nano Banana 2.1 for new projects, and 2.1 is also the cheaper model on DreamTo. The last section compares the documented facts. The details below come from the model page and the API docs.
Endpoint, key and base URL#
The endpoint speaks Google's generateContent protocol on the DreamTo host. Relative to calling Google directly, only the base URL and the key change:
| DreamTo | ||
|---|---|---|
| Base URL | https://generativelanguage.googleapis.com | https://api.dreamto.ai |
| API key | Google AI Studio key | API key from the DreamTo console |
Send the key in either the x-goog-api-key header or Authorization: Bearer; the authentication page has the details. The model ID goes in the URL:
POST https://api.dreamto.ai/v1beta/models/gemini-3.1-flash-image:generateContentUnlike the video models, the docs show no task to create and poll: the quick-start reads the image straight from the response body of the same call. For the async pattern used by video, see the image-to-video guide.
A first request#
This is the docs' own quick-start: a 16:9 image at 2K, response saved to a file.
curl -s -X POST "https://api.dreamto.ai/v1beta/models/gemini-3.1-flash-image:generateContent" \ -H "Authorization: Bearer $DREAMTO_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "contents": [ { "role": "user", "parts": [ { "text": "An elegant dessert in a fancy banana-themed restaurant, soft lighting, food photography" } ] } ], "generationConfig": { "responseModalities": ["TEXT", "IMAGE"], "imageConfig": { "aspectRatio": "16:9", "imageSize": "2K" } } }' > response.jsonThe response is in the Gemini shape: candidates[0].content.parts is a list, and each part carries either text or inlineData. The image is Base64 in inlineData.data. The same call in Python, decoding the image to disk:
import base64import osimport requestsURL = "https://api.dreamto.ai/v1beta/models/gemini-3.1-flash-image:generateContent"HEADERS = {"x-goog-api-key": os.environ["DREAMTO_API_KEY"]}payload = { "contents": [ { "role": "user", "parts": [ {"text": "An elegant dessert in a fancy banana-themed restaurant, soft lighting, food photography"} ], } ], "generationConfig": { "responseModalities": ["TEXT", "IMAGE"], "imageConfig": {"aspectRatio": "16:9", "imageSize": "2K"}, },}response = requests.post(URL, headers=HEADERS, json=payload, timeout=300).json()for part in response["candidates"][0]["content"]["parts"]: if "inlineData" in part: with open("output.png", "wb") as f: f.write(base64.b64decode(part["inlineData"]["data"])) elif "text" in part: print(part["text"])Set a generous client timeout, as the example does with 300 seconds. The page does not give a typical latency for this model, so measure it on your own prompts and sizes.
Parameters#
Everything you can set lives in contents and generationConfig:
| Field | Values |
|---|---|
contents[].parts[].text | The prompt: what to generate or change |
contents[].parts[].inlineData.data | Reference image as Base64, with mimeType image/png, image/jpeg, image/webp, image/heic or image/heif |
contents[].parts[].fileData.fileUri | Reference image as a public https link |
generationConfig.imageConfig.aspectRatio | 1:1, 1:4, 1:8, 2:3, 3:2, 3:4, 4:1, 4:3, 4:5, 5:4, 8:1, 9:16, 16:9, 21:9 |
generationConfig.imageConfig.imageSize | 1K (default), 2K, 4K |
generationConfig.responseModalities | ["TEXT", "IMAGE"] (default) or ["IMAGE"] |
Aspect ratio and size#
The aspect ratio and the size tier together decide the pixel dimensions. The docs do not publish a table of exact pixel counts for this model, so read the dimensions from the returned image instead of hard-coding them. If you omit aspectRatio, text-to-image uses 1:1, and an edit uses the ratio of the input image.
Write the K in uppercase: 1K, 2K, 4K. The catalog's parameter schema lists a 512 option, but the API docs say the official 512px (0.5K) size is not supported yet. Where the two disagree, trust the docs: send 1K, 2K or 4K only.
With 14 ratios, banners (4:1, 8:1), tall strips (1:4, 1:8) and ultra-wide frames (21:9) are one parameter away, so you can ask for the shape of the placement instead of cropping a square.
Text and image output#
responseModalities defaults to ["TEXT", "IMAGE"], so the model may return a short text part alongside the image. For a pipeline that only wants pixels, send ["IMAGE"] and skip the text branch in your parser.
Reference images and editing#
To edit or build on existing pictures, add image parts before or after the text part in the same parts array. Send each reference either as Base64 in inlineData or as a public link in fileData. A link-based edit looks like this:
curl -s -X POST "https://api.dreamto.ai/v1beta/models/gemini-3.1-flash-image:generateContent" \ -H "x-goog-api-key: $DREAMTO_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "contents": [ { "role": "user", "parts": [ { "fileData": { "fileUri": "https://example.com/product.jpg" } }, { "text": "Keep the bottle exactly as it is and place it on a pale stone ledge with soft window light" } ] } ], "generationConfig": { "responseModalities": ["IMAGE"], "imageConfig": { "imageSize": "2K" } } }' > edit.jsonThe URL must be reachable from the public internet over https; if your files are private, use inlineData instead. Here aspectRatio is left out on purpose, so the output inherits the input image's ratio.
On the reference limit, the page says Google recommends up to 10 object images plus 4 character images, and our catalog lists 14 references for this model. The docs state it as a recommendation rather than a hard cap, so treat 14 as the planning number and test before relying on more. Nano Banana 2.1's page, by comparison, states the same split as a limit.
The model page describes conversational multi-turn editing and multi-image composition as supported. It does not show the multi-turn request shape for this model, so this guide does not either. For worked editing patterns, see image editing with Nano Banana and combining several images, and for prompt wording the Nano Banana prompt guide.
What the endpoint rejects#
Three official Gemini parameters are not supported yet. They return 400, the model is not called and nothing is charged:
| Parameter | What to do instead |
|---|---|
systemInstruction | Put the instructions in the prompt text |
safetySettings | None; the default thresholds apply |
tools | Grounding with Google Search (google_search) is not available |
Our catalog lists search grounding among the model's Google-side features, but it is not available through DreamTo yet. Also unsupported: the Batch API, and files/... references from Files API uploads. Use inlineData or a public fileData.fileUri instead.
Errors use the DreamTo error envelope, not Google's status envelope. Branch on the HTTP status first: 401 for a missing or invalid key, 402 for insufficient balance, 429 for rate limits (back off and retry), 400 for a request the model cannot take. The full table is on the errors page, and handling DreamTo API errors covers retries. Invalid requests and failed generations are not charged.
Price#
Nano Banana 2 is billed per request, by size. As of December 2026, the prices a customer pays are:
| Size | Price per request |
|---|---|
| 1K | $0.02 per request |
| 2K | $0.03 per request |
| 4K | $0.045 per request |
So 100 images at 2K cost 100 x $0.03 = $3.00. Current prices are always on the prices page. The aspect ratio does not change the price in the catalog; only the size does.
Nano Banana 2 or 2.1#
The model page itself says Nano Banana 2 is the model that 2.1 updates, and the catalog says Google now recommends 2.1 for new projects. Here are the documented facts side by side, with prices as of December 2026:
| Nano Banana 2 | Nano Banana 2.1 | |
|---|---|---|
| Model ID | gemini-3.1-flash-image | gemini-nano-banana-2.1 |
| Aspect ratios | 14 | 14 |
| Sizes | 1K, 2K, 4K | 1K, 2K, 4K |
| Reference images | Google recommends up to 10 object plus 4 character | Up to 14: 10 object plus 4 character |
| 1K / 2K / 4K price | $0.02 / $0.03 / $0.045 per request | $0.01 / $0.02 / $0.03 per request |
On these facts, a new project has little reason to start on Nano Banana 2. It is the right call if you already run it and your outputs are tuned to it; the request shape is the same, so moving later means changing the model ID in the URL. The Nano Banana 2.1 guide walks through that model, which Nano Banana model to use covers the whole family, and the image API chooser puts it next to GPT and Seedream. You can try a prompt in the Nano Banana 2 playground before writing code, and browse everything else under models.
FAQ#
What is the Nano Banana 2 model ID?#
The ID is gemini-3.1-flash-image, and it goes in the URL of POST https://api.dreamto.ai/v1beta/models/gemini-3.1-flash-image:generateContent. On the site its slug is gemini-3-1-flash-image, which is the one used in model page links.
What sizes and aspect ratios does Nano Banana 2 support?#
Sizes are 1K (the default), 2K and 4K, with an uppercase K. The 512px size from Google's own documentation is not supported yet. There are 14 aspect ratios, from 1:8 and 1:4 to 4:1, 8:1 and 21:9.
How much does a Nano Banana 2 image cost?#
As of December 2026 it is $0.02 per request at 1K, $0.03 per request at 2K and $0.045 per request at 4K. Invalid requests and failed generations are not charged. See the prices page for current numbers.
Can I use Google Search grounding or a system instruction?#
Not yet. tools (including google_search), systemInstruction and safetySettings all return 400 and are not charged. Put your instructions in the prompt text instead.
How do I send a reference image?#
Add an inlineData part with the Base64 data and its mimeType, or a fileData part with a public https link in fileUri. Supported types are PNG, JPEG, WebP, HEIC and HEIF. References uploaded through the Files API (files/...) are not supported.
Is the request synchronous?#
In the docs' quick-start, one generateContent call returns the image as Base64 in the response body; there is no task to poll. Use a long client timeout, such as the 300 seconds in the docs example.


