The Nano Banana Pro API lets you generate and edit images from your own code, using the Gemini 3 Pro Image model, and you pay for each image you create. You need an API key from Google AI Studio, billing switched on, and a few lines of Python or JavaScript. This guide covers how to get a key and keep it safe, a working quickstart, the settings that matter, reported prices and the mistakes that cause most errors. Model names and prices change, so check Google’s developer pages before you build anything big.
Nano Banana Pro API: the short answer
Get an API key in Google AI Studio, enable billing, install Google’s GenAI SDK and call the Pro image model with a prompt. Reported prices are about $0.134 per image at 1K and 2K resolution and $0.24 at 4K, with a batch option at roughly half price. The model is often listed as gemini-3-pro-image-preview, but names change, so confirm the current ID in Google’s documentation.
Key takeaways
- You need a Gemini API key. Store it in an environment variable, never in your code or in a public repository.
- Pro is built for hard jobs: precise text, many reference images and up to 4K output.
- Prices reported by comparison sites: $0.134 per 1K or 2K image, $0.24 per 4K image, about half for batch.
- Editing costs about the same as generating.
- Every image includes Google’s invisible SynthID watermark.
- Test with the cheaper Nano Banana 2 model first and switch to Pro when a prompt demands it.
What you need before you start
| Requirement | Details |
|---|---|
| Google account | Sign in to Google AI Studio |
| API key | Created in the API keys section of AI Studio |
| Billing | Reports say a paid setup with a card is required for the Pro image model |
| Language | Python or JavaScript are the usual choices, or plain REST calls |
| SDK | Google’s GenAI SDK (the google-genai package for Python) |
| Budget | A spending limit or alert you control |
If you only want to make a few pictures, you don’t need the API at all. The Gemini app does the same job with a subscription. Read our Nano Banana Pro price guide to compare the two routes.
Step 1: get an API key
- Open Google AI Studio and sign in.
- Create a project or link an existing Google Cloud project.
- Switch on billing for that project if the model you want requires it.
- Go to the API keys section and create a key.
- Copy the key once and store it somewhere safe.
Step 2: keep your key safe
A leaked key can run up a bill within minutes. Treat it like a password.
- Store it in an environment variable or a
.envfile, and add that file to.gitignore. - Never paste it into front-end code, a public repository, a screenshot or a chat.
- Set a budget alert and, where possible, restrict what the key can do.
- Create separate keys for testing and production, and delete keys you no longer use.
- Rotate a key immediately if you think it has been exposed.
One tutorial we checked used two different variable names for the key in one example (GOOGLE_API_KEY and GEMINI_API_KEY). If your script says the key is missing, check that the name in your code matches the name in your environment.
Step 3: run your first image request
This is a minimal Python example based on a published tutorial. Treat it as a pattern and check Google’s current documentation for exact names.
import os
from google import genai
from google.genai import types
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
response = client.models.generate_content(
model="gemini-3-pro-image-preview",
contents="A watercolour fox in a snowy forest",
config=types.GenerateContentConfig(
response_modalities=["TEXT", "IMAGE"],
image_config=types.ImageConfig(aspect_ratio="16:9", image_size="2K"),
),
)
for part in response.parts:
image = part.as_image()
if image:
image.save("fox.png")
Install the package first with pip install google-genai. The response can contain both text and image parts, which is why the loop checks each part. If nothing saves, print the whole response and look for a safety message.
The settings that matter
| Setting | What it does | Tip |
|---|---|---|
| Response modalities | Asks for text, image or both | Include image or you may get text only |
| Aspect ratio | Shape of the picture, such as 1:1, 16:9 or 9:16 | Choose it up front, because cropping later wastes money |
| Image size | 1K, 2K or 4K output | Use 1K or 2K for drafts and 4K only for final files |
| Reference images | Pass images with your prompt for edits and consistency | Reports say Pro can blend many references, but check the current limit |
| Search grounding | Lets the model use Google Search for facts | Useful for current subjects, and it may add a small fee |
| Chat sessions | Keep a conversation for step-by-step edits | Good for iterating without repeating context |
Editing an image with the API
To edit, you send your original image together with a text instruction. The pattern is the same as the app: say what to change and what must stay the same. For example: “Replace the background with a plain light-grey wall. Keep the person and clothing exactly the same.” Pass the image as an input part followed by the text. Editing costs about the same as generating a new image, so refine your instruction before you run it many times. Prompt wording matters just as much here, so keep our Nano Banana prompt guide open.
What it costs
| Item | Reported price |
|---|---|
| Pro, 1K or 2K image | $0.134 |
| Pro, 4K image | $0.24 |
| Pro batch, 1K or 2K | About $0.067 |
| Pro batch, 4K | About $0.12 |
| Reference image input | A small extra cost per image |
Treat these as a guide drawn from comparison sites and tutorials, not Google’s checkout. Batch jobs run asynchronously and cost less, which suits large overnight runs. Rate limits depend on your account tier and region. One tutorial mentioned a free image allowance in AI Studio, while another source said the Pro model has no free API tier, so assume you will pay and check your own account.
Common errors and fixes
| Problem | Likely cause | Fix |
|---|---|---|
| Authentication error | Wrong or missing key | Check the variable name and the key value |
| Permission or billing error | Billing not enabled | Turn on billing for the project |
| Model not found | Old or misspelled model ID | Copy the current ID from Google’s docs |
| Text only, no image | Image output not requested | Add the image response modality |
| Blocked or empty response | Safety filter | Reword the prompt and remove real names or sensitive content |
| Rate limit message | Too many requests | Slow down, retry with a delay or use batch |
| Costs higher than expected | Many retries or 4K output | Test at 1K, add budget alerts |
Good habits for production
- Log each request’s prompt, settings and cost so you can audit them.
- Cache results instead of regenerating identical images.
- Check outputs before showing them to customers, especially faces and text.
- Respect Google’s usage policies: don’t create deceptive images of real people.
- Tell users when images are AI-generated if it matters, and keep SynthID intact.
Frequently asked questions
What is the Nano Banana Pro API?
It is access to Google’s Gemini 3 Pro Image model through the Gemini API, so your own code can generate and edit images. You send a prompt, optionally with reference images, and receive image data back. You pay for each image generated.
How do I get a Nano Banana Pro API key?
Sign in to Google AI Studio, create or link a Google Cloud project, switch on billing if required, open the API keys section and create a key. Store it in an environment variable and never commit it to a public repository.
How much does the Nano Banana Pro API cost?
Reported prices are about $0.134 per image at 1K and 2K resolution and $0.24 at 4K, with batch pricing about half. Prices change, so confirm them on Google’s official pricing page and set a budget alert before running large jobs.
What is the Nano Banana Pro model ID?
Tutorials list it as gemini-3-pro-image-preview, but model names change and older names get retired. Copy the current ID from Google’s documentation, and update your code if you get a model-not-found error.
Can I edit images with the Nano Banana Pro API?
Yes. Send your original image together with a text instruction saying what to change and what to keep. Editing is reported to cost about the same as generating a new image, so refine the instruction before running many attempts.
Is the Nano Banana Pro API free?
Treat it as paid. One source says the Pro model has no free API tier, while a tutorial mentions a free allowance in AI Studio. Rules change, so check your own account and keep spending alerts on while you test.
Start small, then scale
Create a key, run one request and read the bill before you build a pipeline. More model guides are in the Gemini and Nano Banana section, and our Nano Banana Pro explainer covers what the model is good at. We are independent of Google, and the how we test page shows how we check technical claims. When you’re ready for more, head back to the homepage.
Independent publication. Not affiliated with or endorsed by Google. Limits and prices change; verify in your own account.
