API guides

Nano Banana 2.1 API guide: generate and edit images

Call gemini-nano-banana-2.1 through DreamTo: generateContent requests, 14 aspect ratios, 1K to 4K output, 14 reference images, multi-turn edits and prices.

A painted seed pod splits open on a mossy stone in a glasshouse, releasing glowing seeds into warm, misty light
On this page

Nano Banana 2.1 is Google's update to Nano Banana 2, and on DreamTo its model ID is gemini-nano-banana-2.1. You call it with one synchronous generateContent request: a prompt, up to 14 optional reference images, a size of 1K, 2K or 4K and one of 14 aspect ratios. The image comes back as Base64 in the response body. This guide covers the request, every parameter, editing with input images and multi-turn conversations, what the endpoint rejects, errors and prices.

The facts come from the model page and the API docs. If you would rather try prompts first, the playground takes the same parameters without code.

Setup: base URL, key and endpoint#

The endpoint follows Google's generateContent protocol on the DreamTo host. Compared with calling Google directly, only the base URL and the key change.

GoogleDreamTo
Base URLhttps://generativelanguage.googleapis.comhttps://api.dreamto.ai
API keyGoogle AI Studio keyDreamTo API key

Create the key in the DreamTo console and send it in the x-goog-api-key header or as Authorization: Bearer (see authentication). There is one endpoint:

text
POST https://api.dreamto.ai/v1beta/models/gemini-nano-banana-2.1:generateContent

Note the dot in the model ID; the URL slug on the site, gemini-nano-banana-2-1, uses a hyphen. The call is synchronous: there is no task ID to poll and no webhook to set up, so the generated image is in the HTTP response. The docs cover generateContent only. The Batch API and files/... references from Files API uploads are not supported yet.

A first text-to-image request#

This is the docs' quick-start request: a 16:9 image at 2K, response saved to a file.

bash
curl -s -X POST "https://api.dreamto.ai/v1beta/models/gemini-nano-banana-2.1: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.json

In the response, candidates[0].content.parts is a list, and each part carries either text or inlineData. The Base64 image is in inlineData.data, next to its mimeType. The same request in Python, decoding the image:

python
import base64import osimport requestsURL = "https://api.dreamto.ai/v1beta/models/gemini-nano-banana-2.1: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"])

Loop over the parts rather than reading index 0, because with the default modalities the reply can contain text as well as the image. A part with thought set to true belongs to the model's thinking, not to the final result, so skip it when saving. finishReason is STOP after a normal finish. NO_IMAGE means no image was generated, and the docs say to adjust the prompt and retry; IMAGE_SAFETY and IMAGE_PROHIBITED_CONTENT mean the generated image failed the safety check or contains prohibited content.

Request parameters#

These are the fields the docs list for this model.

FieldValues
contents[].parts[].textThe prompt: what to generate or change
contents[].parts[].inlineData.dataReference image as Base64, with mimeType of image/png, image/jpeg, image/webp, image/heic or image/heif
contents[].parts[].fileData.fileUriReference image as a public https link
generationConfig.imageConfig.aspectRatio1: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.imageSize1K (default), 2K, 4K
generationConfig.responseModalities["TEXT", "IMAGE"] (default) or ["IMAGE"]

imageSize: 1K, 2K or 4K#

imageSize defaults to 1K. The K must be uppercase; lowercase is rejected. For a 1:1 image the three tiers are 1024x1024, 2048x2048 and 4096x4096 pixels. The size is also what sets the price, as the last sections show. The catalog's advice is to judge subject placement and whitespace on an early draft, then check local details and lettering at the size you will deliver.

aspectRatio: 14 ratios, two defaults#

The aspect ratio and the size tier together set the pixel dimensions. At 1K the docs give these:

aspectRatioPixels at 1KShape
1:11024x1024Square
1:4512x2048Extra tall
1:8384x3072Extreme tall
2:3848x1264Portrait
3:21264x848Landscape
3:4896x1200Portrait
4:12048x512Extra wide
4:31200x896Landscape
4:5928x1152Portrait
5:41152x928Landscape
8:13072x384Extreme wide
9:16768x1376Vertical
16:91376x768Widescreen
21:91584x672Ultra-wide

If you leave aspectRatio out, text-to-image returns 1:1 and an edit keeps the ratio of the input image. To change the framing of an edit, set the ratio yourself. The docs also say this version fixes tiling artifacts on wide and panoramic ratios (1:4, 4:1, 1:8, 8:1) at 2K and 4K, which matters for banners and tall strips.

responseModalities#

The default ["TEXT", "IMAGE"] returns text and images. Send ["IMAGE"] when you only want the picture.

Editing with input images#

An edit is a text part plus one or more image parts in the same user turn. A part sets exactly one of text, inlineData or fileData. The docs allow up to 14 reference images per request: at most 10 object images and 4 character images, and the model description mentions consistency for up to 4 characters and 10 objects.

Send an image either as Base64 in inlineData (with data and mimeType both present, and no data: prefix) or as a public https link in fileData.fileUri. This request replaces a background and keeps the subject, using a link:

python
import base64import osimport requestsURL = "https://api.dreamto.ai/v1beta/models/gemini-nano-banana-2.1:generateContent"HEADERS = {"x-goog-api-key": os.environ["DREAMTO_API_KEY"]}payload = {    "contents": [        {            "role": "user",            "parts": [                {"text": "Replace the background with a neon street after rain; keep the person unchanged"},                {"fileData": {"fileUri": "https://example.com/portrait.jpg"}},            ],        }    ],    "generationConfig": {"responseModalities": ["IMAGE"], "imageConfig": {"imageSize": "1K"}},}response = requests.post(URL, headers=HEADERS, json=payload, timeout=300).json()for part in response["candidates"][0]["content"]["parts"]:    if part.get("thought"):        continue    if "inlineData" in part:        with open("edited.png", "wb") as f:            f.write(base64.b64decode(part["inlineData"]["data"]))

Replace the example URL with a real, publicly downloadable image. Here aspectRatio is omitted on purpose, so the result keeps the input's ratio.

Several references with different roles#

With more than one image, say in the prompt what each one is for ("the product from the first image, the backdrop from the second"). The catalog's tip is the same: give each reference one primary role, such as subject, composition sketch or colour and light, so that when something comes out wrong you know which instruction to correct.

Local edits#

The request fields above include no mask parameter, so a local edit is done with words. The catalog suggests naming the region and its edge ("the backdrop on the subject's right") and listing the text and outlines that must stay, then comparing the areas outside the edit with the original after generation.

Multi-turn editing#

The model supports conversational editing. contents holds the turns in order: the earlier user turn, the model's reply with role set to model, then the new user turn. Send the model's parts back unchanged. Output parts can carry a thoughtSignature, and the docs ask for it to be returned as it arrived.

python
import base64import osimport requestsURL = "https://api.dreamto.ai/v1beta/models/gemini-nano-banana-2.1:generateContent"HEADERS = {"x-goog-api-key": os.environ["DREAMTO_API_KEY"]}CONFIG = {"responseModalities": ["TEXT", "IMAGE"], "imageConfig": {"imageSize": "1K"}}history = [    {        "role": "user",        "parts": [{"text": "A ceramic coffee mug on a walnut table, morning window light, product photo"}],    }]def call(contents):    r = requests.post(URL, headers=HEADERS, json={"contents": contents, "generationConfig": CONFIG}, timeout=300)    r.raise_for_status()    return r.json()["candidates"][0]["content"]first = call(history)history.append({"role": "model", "parts": first["parts"]})history.append({"role": "user", "parts": [{"text": "Same mug and table, but make the light warmer and add steam above the cup."}]})second = call(history)for part in second["parts"]:    if part.get("thought"):        continue    if "inlineData" in part:        with open("mug-edit.png", "wb") as f:            f.write(base64.b64decode(part["inlineData"]["data"]))

Each turn is its own request at the per-request price, and the body grows with every Base64 image carried in the history. If the starting image did not come from the model, or you only need one change, the single-turn form above keeps requests small.

For the order of passes, the catalog's use cases suggest settling placement and lighting first and revising the background and the headline in separate passes, checking silhouette, colours and wording after each one. Its note on character work is to keep one role reference and change only the pose, lighting or backdrop per pass.

Parameters that return 400#

Three official Gemini parameters are not supported yet. A request that includes one returns 400; the model is not called and nothing is charged.

ParameterWhat to do instead
systemInstructionPut the instructions in the prompt
safetySettingsCustom thresholds are not supported; the defaults apply
toolsGrounding with Google Search (google_search) is not supported

If you port code from the official Gemini SDK, remove these three fields first.

Errors and what gets charged#

Errors use the DreamTo error envelope, not Google's status envelope. The body is an error object with code, http_status, message, request_id and type. Branch on the HTTP status and error.code, not on the message text.

HTTPerror.codeMeaning
400invalid_requestMalformed JSON, a missing field or a parameter the model does not support
401unauthorizedMissing or invalid API key
402insufficient_balanceInsufficient balance; top up and retry
429rate_limit_exceededRate limit exceeded; back off and retry
500 / 502 / 503 / 504api_error, service_unavailableInternal error or the model is temporarily unavailable; retry later

A few errors returned by the model side directly may carry only code and message, and code can be the numeric status. Rely on the HTTP status and the X-Request-Id response header, which you should include when you report a problem. Invalid requests and failed generations are not charged. The full table is in the errors docs; the general key and header rules are in the authentication docs.

Prices per request#

As of December 2026, gemini-nano-banana-2.1 is billed per request, in US dollars, and the price depends on imageSize:

imageSizePrice per request
1K$0.01
2K$0.02
4K$0.03

These are the numbers on /prices today and they can change, so check that page before you budget. A batch of 4 images at 2K is 4 x $0.02 = $0.08. Each turn of a multi-turn edit is a separate request, so a first image plus two revisions at 1K is 3 x $0.01 = $0.03.

Where it fits in the family#

Nano Banana Pro uses the same generateContent request shape, so switching means changing the ID in the URL. Pro's reference limits differ and it offers fewer ratios; the Nano Banana Pro guide lists them. For a side-by-side of all four models, read Nano Banana 2.1 vs Pro vs 2 vs 2 Lite. Wording for prompts is in the Nano Banana prompt guide, and a wider view of editing by prompt, mask or reference is in Image editing with Nano Banana. The rest of the catalog is at /models.

FAQ#

What is the model ID for Nano Banana 2.1 on DreamTo?#

It is gemini-nano-banana-2.1, with a dot, used in the URL POST https://api.dreamto.ai/v1beta/models/gemini-nano-banana-2.1:generateContent. The model page on the site uses the slug gemini-nano-banana-2-1.

What sizes and aspect ratios does Nano Banana 2.1 support?#

imageSize takes 1K (default), 2K or 4K with an uppercase K. aspectRatio takes 14 values, from 1:8 to 8:1, including 21:9. If omitted, text-to-image returns 1:1 and an edit keeps the input image's ratio.

How many reference images can I send?#

Up to 14 per request, including up to 10 object images and 4 character images. Send them as Base64 in inlineData or as a public https link in fileData.fileUri. Supported types are PNG, JPEG, WebP, HEIC and HEIF.

Is the API asynchronous?#

No. generateContent is synchronous, and the image is returned in the response as Base64. There is no task to poll and no callback to configure.

Can I use systemInstruction or Google Search grounding?#

Not yet. systemInstruction, safetySettings and tools all return 400, nothing is charged, and the model is not called. Put instructions in the prompt instead.

How much does Nano Banana 2.1 cost?#

As of December 2026 it is $0.01 per request at 1K, $0.02 at 2K and $0.03 at 4K. Invalid requests and failed generations are not charged. Current prices are on /prices.

  • Nano Banana
  • API Guide