Google's image models have a naming problem. The one everyone calls Nano Banana Pro is officially Gemini 3 Pro Image. The model ID in most code samples floating around — gemini-3-pro-image-preview — is retired. And the API call those samples use isn't the one Google's documentation shows anymore. If you tried Nano Banana Pro from code in the last few months and got a 404, that is probably why.

This tutorial fixes all three. You will build a working image pipeline on the current API: generate from text, control size and shape, edit real photos, iterate without starting over, lock a product or character across a whole shoot, ground images in live search results, and generate an illustrated story in a single call. Every snippet below was checked against Google's official image-generation documentation and the google-genai Python SDK (version 3.7.0) on December 5, 2026 — and every function was run locally against the real SDK to confirm the calls are shaped correctly.

The timing matters. Nano Banana 2.1, the cheaper sibling, launched on October 6, and the family now covers the whole range from free sketches to production assets. Pro is the top tier: it reasons about the image before drawing it, which is why it handles the jobs cheaper models fumble — legible text in posters, a product that looks identical in ten different scenes, an infographic whose facts are actually right.

What you'll need#

  • Python 3.10 or newer, and pip. Everything here runs on a laptop; no GPU, no local model.
  • A Gemini API key from Google AI Studio. Pro has no free tier on the API — you need a paid key. You can try the same model free in AI Studio first, and in Google Flow, before spending anything.
  • The SDK: pip install --upgrade google-genai pillow. This tutorial was verified with google-genai 3.7.0.
  • A budget of about $3. A Pro image costs $0.134 at 1K or 2K and $0.24 at 4K; each input image you send costs about a tenth of a cent. Following every step below generates roughly a dozen images and lands under $3.
  • Your own images to edit — a product photo, a portrait, a room shot. You need the rights to anything you upload.

One warning before you start: every image Pro generates or edits carries an invisible SynthID watermark identifying it as AI-generated. That is a feature, not a bug — but it means these images are not a way to pass AI work off as a photograph.

Step 1: Your first image#

The current API is the Interactions API. You create a client, call client.interactions.create() with the model ID gemini-3-pro-image, and read the image back from interaction.output_image.data as base64. The client reads your key from the GEMINI_API_KEY environment variable, so never paste the key into your code.

export GEMINI_API_KEY="your-key-from-ai-studio"
pip install --upgrade google-genai pillow
import base64
from google import genai

client = genai.Client()  # reads GEMINI_API_KEY from the environment

interaction = client.interactions.create(
    model="gemini-3-pro-image",
    input="A ceramic coffee mug on a wooden table in a sunlit cafe, "
          "steam rising, shallow depth of field, photorealistic",
)

image = interaction.output_image
with open("mug_cafe.png", "wb") as f:
    f.write(base64.b64decode(image.data))
print("saved mug_cafe.png")

Run it. The call takes a few seconds — Pro thinks before it draws, and that thinking is the whole point of the premium tier. If you get an error, check two things first: the model ID is exactly gemini-3-pro-image (no -preview suffix), and your key has billing enabled. Pro is not on the free tier, and a free-tier key fails here even though it works fine for text models.

Save this pattern. Every later step is a variation of it: same call, different input and response_format.

Step 2: Control size, shape, and format#

Left alone, Pro matches the output size to your input image, or generates a 1:1 square when there is no input. You control the output with response_format: aspect_ratio and image_size (1K, 2K, or 4K). Set the format explicitly on every call — defaults are the most common source of surprises.

interaction = client.interactions.create(
    model="gemini-3-pro-image",
    input="A wide hero image for a bakery website: croissants and "
          "sourdough on a marble counter, morning light",
    response_format={
        "type": "image",
        "aspect_ratio": "16:9",
        "image_size": "2K",
        "mime_type": "image/jpeg",
    },
)

Aspect ratios Pro supports include 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, and 21:9 — the wide and tall formats cover website heroes, phone wallpapers, and social posts without cropping. The extreme ratios (1:4, 4:1, 1:8, 8:1) exist on the cheaper 2.1 model, not Pro, so don't plan a banner around them on this tier.

Resolution is a cost decision, not just a quality one. A 1K or 2K image costs $0.134; the same image at 4K costs $0.24, nearly double, for pixels most screens never show. The workflow that works: draft and iterate at 1K, then re-run the final prompt at 2K or 4K once. Step 8 turns that into a habit.

Three-stage illustration of the Nano Banana Pro workflow: a prompt card, a reasoning brain, and a finished framed image
AI-generated illustration: prompt, reasoning, finished image — the three stages of every Nano Banana Pro call.

Step 3: Edit a real photo#

Editing is the same call with image parts added to the input: a text instruction plus the image, base64-encoded. The model changes what you asked for and leaves the rest alone — that is the practical difference between Pro and a text-to-image model with an edit mode bolted on.

import base64
from pathlib import Path

def edit(prompt, image_paths, out_path):
    parts = [{"type": "text", "text": prompt}]
    for path in image_paths:
        parts.append({
            "type": "image",
            "data": base64.b64encode(Path(path).read_bytes()).decode(),
            "mime_type": "image/png" if path.endswith(".png") else "image/jpeg",
        })
    interaction = client.interactions.create(
        model="gemini-3-pro-image",
        input=parts,
        response_format={"type": "image"},
    )
    Path(out_path).write_bytes(base64.b64decode(interaction.output_image.data))
    return out_path

edit(
    "Replace the plain white background with a warm terracotta studio "
    "backdrop. Keep the mug exactly as it is.",
    ["mug_cafe.png"],
    "mug_studio.png",
)

Two details matter here. First, each input image costs 560 tokens, about $0.0011 — negligible next to the output, but it is why you should resize a 12 MB phone photo before sending it rather than paying to ship pixels the model downsamples anyway. Google accepts PNG, JPEG, WebP, HEIC, and HEIF inputs, up to 7 MB per file inline. Second, write the instruction the way you would brief a retoucher: name what changes, then name what must not change. "Keep the mug exactly as it is" is doing real work in that prompt.

Step 4: Iterate without starting over#

One-shot generation punishes you for small fixes: every "make the light warmer" regenerates the whole image and risks losing the version you liked. Pro supports real multi-turn editing. Pass the previous interaction's ID and the model picks up where it left off.

interaction = client.interactions.create(
    model="gemini-3-pro-image",
    input="A vibrant infographic explaining photosynthesis as a recipe, "
          "ingredients on the left, finished dish on the right, "
          "colorful kids-cookbook style",
    response_format={"type": "image", "aspect_ratio": "16:9"},
)

# Second turn: change one thing, keep everything else.
interaction_2 = client.interactions.create(
    model="gemini-3-pro-image",
    input="Translate all the text in this infographic to Spanish. "
          "Do not change any other element.",
    previous_interaction_id=interaction.id,
    response_format={
        "type": "image",
        "mime_type": "image/jpeg",
        "aspect_ratio": "16:9",
        "image_size": "2K",
    },
)
Path("photosynthesis_spanish.jpg").write_bytes(
    base64.b64decode(interaction_2.output_image.data)
)

This is the single most valuable habit in the tutorial. Treat the first call as a draft and the follow-ups as revisions: warmer light, tighter crop, different text, one element swapped. Each turn costs one more image, but it costs far less — in money and frustration — than re-rolling a good image from scratch because one word was wrong. A practical rule: if your edit instruction is longer than your original prompt, you are probably asking for a new image; start a fresh interaction instead.

Step 5: Lock a product or character across a whole shoot#

This is the job Pro exists for. You can pass up to 14 reference images in one call, and Pro keeps up to 5 characters, 6 objects, and 3 style references at high fidelity. The classic use is a product shoot: one photo of the product, ten scenes, zero reshoots.

# Same mug, three listings. One reference photo, three prompts.
edit(
    "Place this exact mug on a wet rock beside a misty mountain lake "
    "at dawn. Keep the mug's shape, glaze, and speckles identical.",
    ["mug_product.jpg"],
    "mug_lake.png",
)
edit(
    "Place this exact mug on a linen-covered table at a farmers market, "
    "morning crowd blurred in the background. Keep the mug identical.",
    ["mug_product.jpg"],
    "mug_market.png",
)
edit(
    "Place this exact mug on a dark slate shelf next to a small plant, "
    "moody studio lighting. Keep the mug identical.",
    ["mug_product.jpg"],
    "mug_moody.png",
)

The reference photo is doing the heavy lifting, so make it count: a clean, front-on shot on a plain background, well lit, no other objects competing for attention. And describe the product's identifying details in words too — "speckled sage-green glaze, rounded handle" — because the text prompt and the reference reinforce each other. When the model still drifts, the fix is usually a better reference photo, not a longer prompt.

The same mechanism works for characters: pass up to five reference images of the same person and the model holds their appearance across scenes. Use your own photos or licensed references, and keep other people's likenesses out of it unless you have permission — the model will do it, and that is exactly why the judgment call is yours.

The same speckled sage-green ceramic mug photographed in two scenes: a sunny cafe table and a misty mountain lake
AI-generated illustration: one product, two scenes — the consistency test Nano Banana Pro is built for.

Step 6: Ground it in reality#

Image models invent confidently. Ask for a map, a chart, or an infographic about a real event and a normal model will draw plausible-looking nonsense. Pro can check Google Search before drawing — add the search tool to the call and it grounds the image in live results.

interaction = client.interactions.create(
    model="gemini-3-pro-image",
    input="Create a clean infographic showing the current top five teams "
          "in the English Premier League by points, with a small bar "
          "chart. Use real, current standings.",
    tools=[{"type": "google_search"}],
    response_format={"type": "image", "aspect_ratio": "16:9"},
)
Path("pl_table.png").write_bytes(
    base64.b64decode(interaction.output_image.data)
)

Grounding is the difference between a decoration and an asset you can publish. The first 5,000 search requests a month are free (shared across Gemini 3 and newer models); after that they cost $14 per 1,000, capped at 1,500 a day. One caveat from Google's own docs: verify the result. Grounding makes the model far more likely to be right; it does not make it incapable of being wrong. Check numbers in an infographic the same way you would check a junior designer's — because the failure mode is identical, a clean-looking chart with one wrong bar.

Step 7: Generate a whole illustrated story in one call#

Pro can return interleaved text and images — a story, a how-to, a storyboard — in a single response. The trap is that interaction.output_image only holds the last image. To get all of them, iterate over interaction.steps and save each image block as it appears.

interaction = client.interactions.create(
    model="gemini-3-pro-image",
    input="Write the story of the lifecycle of a monarch butterfly, "
          "interleave illustrations",
)

n = 1
for step in interaction.steps or []:
    if step.type == "model_output":
        for block in step.content or []:
            if block.type == "text":
                print(block.text)
            elif block.type == "image":
                filename = f"butterfly_lifecycle_{n}.png"
                Path(filename).write_bytes(base64.b64decode(block.data))
                print(f"[Saved illustration: {filename}]")
                n += 1

This is the cheapest way to produce a consistent illustrated sequence — a children's story, a product assembly guide, a comic strip — because one call holds the character and style steady across every panel instead of re-establishing them image by image. If a panel comes out wrong, don't re-run the whole story: take the bad panel's image and fix it with a Step 4 follow-up turn.

Step 8: Keep the bill small#

Pro is priced per image, and the price list is short enough to memorize. Draft on the cheap model, finish on Pro, and never pay for 4K until the image is final.

Model1K image2K image4K imageBest for
Nano Banana Pro (gemini-3-pro-image)$0.134$0.134$0.24Final assets, text-heavy images, product shoots
Nano Banana 2.1 (gemini-nano-banana-2.1)$0.0336$0.0504$0.113Drafts, exploration, high-volume work
Nano Banana (gemini-2.5-flash-image)$0.039 flatLegacy — deprecated, shuts down March 15, 2027

The workflow that follows from those numbers: explore prompts and compositions on 2.1 at 1K, where each try costs three cents; when the composition is right, re-run the winning prompt on Pro at 2K for thirteen cents; only go to 4K for the final print or hero asset. A ten-image product shoot done this way costs roughly $2 instead of $10, and the drafts are usually good enough to show a client before you spend the Pro money.

# Draft cheap, finish premium. Same prompt, two models.
CHEAP = "gemini-nano-banana-2.1"
PRO = "gemini-3-pro-image"

def draft(prompt, out):
    ix = client.interactions.create(model=CHEAP, input=prompt,
        response_format={"type": "image", "image_size": "1K"})
    Path(out).write_bytes(base64.b64decode(ix.output_image.data))

def finish(prompt, out):
    ix = client.interactions.create(model=PRO, input=prompt,
        response_format={"type": "image", "aspect_ratio": "16:9",
                         "image_size": "2K"})
    Path(out).write_bytes(base64.b64decode(ix.output_image.data))

One more cost note: the model's internal "thinking" — the interim thought images it generates while composing — is not charged. You pay for the image you receive, not for the reasoning that produced it.

Which approach should you use?#

Pro is not the right answer to every image job. It is the most expensive model in Google's image family, and the premium only pays when you need what it uniquely does.

  • Use Pro when the image has to be right, not just pretty: text that must be legible, a product or face that must stay identical across scenes, an infographic with real numbers, a final asset a client will see.
  • Use Nano Banana 2.1 when you are exploring — testing ten compositions, building a mood board, generating placeholders, or shipping volume where "close enough" is genuinely enough. It is a quarter of the price at 1K and still supports search grounding and multi-turn editing.
  • Use the Gemini app or AI Studio when there is no code at all: a one-off edit, a quick mockup, trying the model before buying API access. The API is for pipelines, not single images.
  • Look outside Google when the job is something Pro doesn't do: FLUX 3 Image for precise region-by-region edits with bounding boxes, GPT Image 2.6 for animated GIFs and SVG export. Our image tools comparison covers the trade-offs.

Five mistakes that waste your money#

  1. Copying old code samples. The -preview model ID is retired and the generate_content examples predate the Interactions API. If a sample fails, the model ID is the first thing to check.
  2. Generating at 4K while iterating. Every draft at 4K costs nearly double the 2K price for pixels you can't judge on screen. Draft at 1K, finish at 2K, reserve 4K for the final.
  3. Re-rolling instead of refining. A follow-up turn with previous_interaction_id costs one image and keeps everything you liked. A fresh call costs one image and gambles all of it.
  4. Sending full-resolution phone photos as references. Each input image is 560 tokens; resize to a sensible size first. The model downsamples anyway.
  5. Trusting grounded numbers without checking. Search grounding makes facts far more likely to be right, but a wrong bar in a beautiful chart is worse than no chart at all. Verify before you publish.

The takeaway#

Nano Banana Pro earns its premium in exactly three situations: the image contains text that must be right, a subject must look identical across many scenes, or the facts in the image must be real. Everything else is cheaper on 2.1. The API itself is small — one call, one model ID, a response format, and an optional previous-interaction link — and that smallness is the point: the complexity lives in the prompt and the reference images, not in the code around them.

Start with one real job, not a demo prompt. Take a product photo you already have, put it in three scenes, and show the results to whoever cares. If the product holds up across all three, you have a product shoot that used to need a studio. If it doesn't, you have spent forty cents finding out.