nano bananaapidevelopers

Nano Banana 2 API: How to Use It for Your Projects

Nano Banana 2 is Google's fast text-to-image API built for developers integrating AI image generation at scale. This article covers authentication, request formatting, error handling, rate limits, and step-by-step usage on PicassoIA, with working code examples for Python and Node.js.

Nano Banana 2 API: How to Use It for Your Projects
Cristian Da Conceicao
Founder of Picasso IA

If you need to generate images programmatically, the Nano Banana 2 API by Google gives you one of the fastest paths from a text prompt to a production-ready result. Available directly through Google's API infrastructure and through platforms like PicassoIA, nano-banana-2 combines conversational editing, multi-image fusion, and real-time web grounding in a model you can call with a standard HTTP POST request. Whether you are building a content pipeline, shipping a product visualization feature, or prototyping an app that needs AI images on demand, this is how to wire it up correctly.

Developer's hands typing on mechanical keyboard with API terminal visible in background, close-up, warm natural light, photorealistic

What Nano Banana 2 Actually Does

Most text-to-image models operate the same way: you send a prompt, the model returns an image. Nano Banana 2 does that, but it adds three capabilities that change how you architect your integration.

Conversational context means the model remembers what you generated in the same session. You can describe a character once, then issue follow-up requests like "change the background to a rooftop at sunset" or "swap the jacket color to burgundy" and the model carries the visual thread forward without you repeating the full description each time.

Multi-image fusion lets you pass up to 14 reference images in a single request. The model blends elements, visual styles, or characters from each input into a single coherent output. This is particularly useful for brand work where you need consistent faces, logos, or product shots across multiple generated images.

Real-time web grounding connects the generation process to Google Search. If your prompt references something current, such as a recent sporting event, a newly released product, or a seasonal trend, the model pulls fresh visual context from the web rather than relying solely on training data frozen at a cutoff date.

Speed vs. Quality Trade-offs

The "nano" in the name is accurate. This model is optimized for throughput. On typical prompts it generates faster than flux-1.1-pro or sdxl, and the default 1K output is ready for web use instantly. When you need higher fidelity, bumping to 2K or 4K resolution adds latency but delivers results that hold up for print or large-format digital display.

How It Fits in Google's Image Stack

Google offers several text-to-image models. Nano Banana 2 sits between the original nano-banana and the premium nano-banana-pro. For comparison:

ModelBest ForSpeed
nano-bananaQuick drafts, prototypingFastest
nano-banana-2Production apps, pipelinesFast
nano-banana-proHigh-fidelity, commercial outputModerate
imagen-4Maximum quality, editorial workSlower

For most application development scenarios, nano-banana-2 hits the sweet spot.

Woman reviewing API documentation on laptop at sunlit coffee shop, warm natural window light, photorealistic

Setting Up API Access

Getting Your Credentials

Access to the Nano Banana 2 API requires an API token. You obtain this through the Replicate platform, which hosts the model under Google's ownership. After creating an account and generating a token, store it as an environment variable:

export REPLICATE_API_TOKEN="your_token_here"

Never hardcode tokens in source files. If you are deploying on a cloud platform, use your provider's secrets management service instead of .env files.

Understanding the Base URL

The API follows standard REST conventions. All requests go to the Replicate endpoint with the model identifier in the path. The general pattern:

POST https://api.replicate.com/v1/models/{owner}/{model}/predictions

For nano-banana-2, that resolves to:

POST https://api.replicate.com/v1/models/google/nano-banana-2/predictions

Every request must include two headers: Authorization: Bearer {token} and Content-Type: application/json.

Two developers collaborating at standing desk with API architecture diagram on monitor, modern open-plan office, warm mixed lighting, photorealistic

The Core Request Anatomy

Required Parameters

Only one parameter is required to generate an image:

ParameterTypeDescription
promptstringText description of the image you want

That simplicity is intentional. A working request can be as minimal as five lines of JSON:

{
  "input": {
    "prompt": "A modern studio apartment at golden hour, warm light from west-facing windows, wooden floors, minimal furniture"
  }
}

Optional Parameters That Change Results

Where the real control lives is in the optional parameters:

ParameterTypeDefaultNotes
resolutionstring1KOptions: 1K, 2K, 4K
aspect_ratiostringmatch_input_image15 presets, e.g. 16:9, 9:16, 1:1
image_inputarray[]Up to 14 reference image URLs
image_searchbooleanfalseEnables Google Image Search grounding
google_searchbooleanfalseEnables real-time web search grounding
output_formatstringjpgjpg or png

💡 Setting aspect_ratio to 16:9 and resolution to 2K covers the majority of use cases for web content: landing pages, blog headers, and social media banners.

Reading the JSON Response

A successful prediction returns HTTP 201. The response body includes a prediction ID and a status field:

{
  "id": "xyz123abc",
  "status": "starting",
  "urls": {
    "get": "https://api.replicate.com/v1/predictions/xyz123abc",
    "cancel": "https://api.replicate.com/v1/predictions/xyz123abc/cancel"
  }
}

Generation is asynchronous. You poll the get URL until status changes to succeeded, at which point output contains the image URL or base64-encoded data depending on your configuration.

Aerial top-down flat lay of developer desk with notebook, keyboard, sticky notes, code printouts, warm daylight, photorealistic

Code That Works Right Now

Python in Under 20 Lines

The replicate Python client handles the polling loop for you. Install it with pip install replicate, then:

import replicate
import os

client = replicate.Client(api_token=os.environ["REPLICATE_API_TOKEN"])

output = client.run(
    "google/nano-banana-2",
    input={
        "prompt": "A professional product photo of a ceramic coffee mug on a marble surface, soft studio lighting, 4K, photorealistic",
        "resolution": "2K",
        "aspect_ratio": "1:1",
        "output_format": "jpg"
    }
)

# output is a list of FileOutput objects
image_url = str(output[0])
print(image_url)

The client.run() method blocks until the prediction is complete and returns the output directly. For production pipelines, switch to client.predictions.create() and handle the polling yourself so you can process other work while images are generating.

Node.js Async Pattern

For JavaScript developers, the Replicate npm package provides the same abstraction:

import Replicate from "replicate";

const replicate = new Replicate({
  auth: process.env.REPLICATE_API_TOKEN,
});

async function generateImage(prompt, resolution = "1K") {
  const output = await replicate.run("google/nano-banana-2", {
    input: {
      prompt,
      resolution,
      aspect_ratio: "16:9",
      output_format: "jpg",
    },
  });

  return output[0]; // URL to the generated image
}

generateImage("A minimalist home office setup, morning light, wooden desk, single plant")
  .then(url => console.log("Generated:", url))
  .catch(err => console.error("Failed:", err.message));

For high-volume pipelines, use Promise.all() to fan out multiple requests simultaneously rather than awaiting each one in sequence. Nano Banana 2 handles concurrent requests well at the default 1K resolution.

Developer reviewing AI-generated images on tablet sitting on sofa, bright minimalist apartment, natural skylight, photorealistic

How to Use Nano Banana 2 on PicassoIA

If you prefer a no-code or low-code approach for testing before building your integration, PicassoIA gives you direct access to nano-banana-2 through a clean browser interface. This is also a fast way to validate prompts before embedding them in your codebase.

Step 1: Open the Model Page

Go to the nano-banana-2 page on PicassoIA. You will see the prompt field and all optional configuration options laid out directly on the page.

Step 2: Write a Prompt That Works

The prompt is the only required field. Write in plain, descriptive English. Be specific about lighting, setting, mood, and subject matter. Vague prompts produce generic results. Compare these two:

  • Weak: "A woman in a city"
  • Strong: "A woman in her 30s with dark hair wearing a tan trench coat, walking through a rainy Paris street at dusk, wet cobblestones reflecting shop lights, shallow depth of field"

The stronger version gives the model anchors: a person with specific traits, a setting, a time of day, weather conditions, and a photographic property. Nano Banana 2 responds well to this level of detail.

Step 3: Set Resolution and Aspect Ratio

Select your resolution from the resolution dropdown:

  • 1K for social media posts, thumbnails, or rapid iteration
  • 2K for landing pages, blog headers, and product pages
  • 4K for print materials, large-format display, or when you need to crop heavily

Pick the aspect ratio from the 15 available presets. For web banners use 16:9. For portrait-oriented social content use 9:16. For square posts use 1:1.

💡 If you are working with reference images, upload them to the Image Input field. The model reads up to 14 at once and uses them as visual context. This is particularly powerful for maintaining brand consistency across a set of generated images.

Step 4: Enable Web Grounding When Relevant

Toggle Google Search on if your prompt involves current events, real locations, or time-sensitive visual context. Toggle Image Search on if you want the model to pull real web images as visual reference for your subject matter. Both options add a small amount of latency but dramatically improve relevance for contextual prompts.

Step 5: Generate and Download

Click the generate button. Nano Banana 2 is fast at 1K, typically returning results within a few seconds. At 4K, expect 15 to 30 seconds depending on server load. Download your output directly from the result panel.

Close-up of monitor screen displaying Python API code with syntax highlighting, hand entering frame from right, screen as primary light, photorealistic

Errors You Will Hit

Common HTTP Status Codes

Most integration problems come from one of four places: authentication, malformed request bodies, rate limits, or model-specific validation failures.

Status CodeMeaningFix
401Invalid or missing API tokenCheck your Authorization header and token value
422Validation error in inputRead the error message; usually a missing required field or wrong data type
429Rate limit exceededImplement exponential backoff; check your plan's RPM limit
500Server errorRetry once; if it persists, check Replicate's status page

The 422 error is the most common for new integrations. The response body will include a detail field that describes exactly which parameter failed validation and why.

Rate Limits and Staying Within Them

Free-tier accounts on Replicate have a requests-per-minute cap. For production workloads, upgrade to a paid plan or implement a local queue that batches requests rather than firing them all at once.

A simple token bucket pattern in Python:

import time
from collections import deque

class RateLimiter:
    def __init__(self, max_per_minute):
        self.max_per_minute = max_per_minute
        self.requests = deque()

    def wait_if_needed(self):
        now = time.time()
        while self.requests and self.requests[0] < now - 60:
            self.requests.popleft()
        if len(self.requests) >= self.max_per_minute:
            sleep_time = 60 - (now - self.requests[0])
            time.sleep(sleep_time)
        self.requests.append(time.time())

Wrap every API call with rate_limiter.wait_if_needed() before making the request and you will never hit a 429 in a production pipeline.

Creative professional woman reviewing AI-generated image gallery on studio monitor, north-facing skylight, warm skin tones, photorealistic

What You Can Build With This API

E-Commerce Product Mockups

Instead of scheduling a product photography session every time you add a SKU, you can generate contextual product photos on demand. Pass your product image via image_input, describe the setting you want (a kitchen counter, a café table, an outdoor lifestyle scene), and nano-banana-2 composites the product into a photorealistic environment. For product lines with multiple colorways, generate one base scene and use the conversational editing feature to swap colors in follow-up requests without re-running a full generation each time.

Content Marketing Pipelines

Blog post workflows that previously required a designer can route through the API instead. At publication time, your CMS sends the article title and topic to the API, receives an image, and attaches it to the post automatically. For campaigns tied to trending topics, enable google_search grounding so images reflect what is actually happening rather than what the model learned during training.

App Prototyping With Real Images

Placeholder images slow down design reviews. When you wire nano-banana-2 into your prototyping workflow, every screen in your mockup shows a contextually relevant generated image instead of gray boxes. Describe the section's content and let the API fill it. Stakeholders see realistic layouts and give more actionable feedback.

Server rack in modern data center, low-angle shot, matte black hardware, cool fluorescent lighting, technician with checklist in background, photorealistic

Multi-Model Workflows

Nano Banana 2 does not have to operate alone. A common architecture pairs it with other models for sequential processing: use nano-banana-2 to generate a draft quickly, then pass the output to a super-resolution model to upscale it for print. Or generate an image with nano-banana-2, then use an inpainting model to refine specific regions without regenerating the entire composition.

PicassoIA gives you access to all of these models in one place, including gpt-image-1.5 for instruction-following tasks and flux-2-pro for high-fidelity photorealistic output when maximum quality is required.

The Right Parameters for Different Projects

Different project types call for different configurations. Here is a reference table:

Project TypeResolutionAspect RatioWeb Grounding
Social media post1K1:1 or 9:16Off
Blog header2K16:9Off
Product mockup2K1:1 or 4:3Off
Event-related content1K16:9On (Google Search)
Brand consistency work2KYour brand ratioOff + image_input
Print materials4K4:3 or customOff

When working with reference images via image_input, include at least two images if you want the model to pick up on a visual style. A single reference image often results in direct imitation rather than style adoption. Multiple references push the model to identify the common visual thread across them.

Smartphone held in hand displaying mobile app with AI-generated portrait gallery, warm desk background, shallow depth of field, photorealistic

Start Generating on PicassoIA Today

The fastest way to see what nano-banana-2 can do for your specific use case is to run a few prompts before writing any integration code. PicassoIA gives you immediate access to the model at this link, with all parameters visible and adjustable in one interface.

Try a prompt that matches your actual production use case. Check the output at 1K first for speed, then bump to 2K or 4K once you have a prompt that produces the visual style you want. Once you find a configuration that works, replicate it in your API calls exactly and you will get consistent results at scale.

If you need higher fidelity output for commercial work, test nano-banana-pro against nano-banana-2 with the same prompts and compare the results side by side. The quality difference is visible at 4K and matters for print or large-format display.

Beyond image generation, PicassoIA also offers over 87 video generation models, super-resolution tools for upscaling your outputs, and background removal for e-commerce workflows. Everything works through the same interface or API.

Startup team in glass-walled conference room with wireframes, laptops, and API flowchart on whiteboard, warm afternoon light, photorealistic

Share this article