Nano Banana 2 API Guide: Integrate Google's Efficient Image Model
You're generating images at scale — product photos, marketing assets, app avatars — and the per-image cost is eating into your margins. You need a model that produces solid output without the price tag of premium tiers. Nano Banana 2, Google's efficient second-generation image model, is available through GenRelay at $0.020 per 1K-resolution image. This guide walks you from zero to a working integration in under 30 minutes.
What Is Nano Banana 2?
Nano Banana 2 is Google's second-generation efficient text-to-image model, designed for high-throughput, cost-effective image generation. It's accessible through GenRelay, a unified generative media API that provides a single endpoint for multiple image and video models — no separate credentials or SDK per provider.
As of August 2026, GenRelay offers three image models:
| Model | 1K | 2K | 4K |
|---|---|---|---|
| Nano Banana 2 | $0.020 | — | $0.036 |
| Nano Banana Pro | $0.030 | $0.030 | $0.042 |
| GPT-image-2 | $0.014/pic | — | — |
Nano Banana 2 sits between GPT-image-2 (cheapest, single fixed resolution) and Nano Banana Pro (higher quality ceiling, 2K option). It gives you resolution flexibility — 1K for web, 4K for print — without paying for Nano Banana Pro's quality headroom when you don't need it. For a detailed quality comparison, see Nano Banana Pro vs Nano Banana 2.
How Do I Authenticate with the GenRelay API?
Authentication uses a standard HTTP Bearer token. Generate your API key in the GenRelay console under API Keys, then include it in every request header:
Authorization: Bearer YOUR_GENRELAY_KEY
One key covers all models on the platform — Nano Banana 2, Nano Banana Pro, GPT-image-2, and all video models. No per-model credentialing.
How Do I Make My First Nano Banana 2 Request?
Send a POST to https://genrelay.ai/v1/images/generations with "model": "nano-banana-2". Here's a minimal working example:
import requests
response = requests.post(
"https://genrelay.ai/v1/images/generations",
headers={
"Authorization": "Bearer YOUR_GENRELAY_KEY",
"Content-Type": "application/json",
},
json={
"model": "nano-banana-2",
"prompt": "Studio product photo of a white ceramic coffee mug on a marble surface, soft shadows, neutral background",
"size": "1024x1024",
"n": 1,
},
timeout=60,
)
response.raise_for_status()
data = response.json()
image_url = data["data"][0]["url"]
print(f"Generated image: {image_url}")
The response follows the OpenAI-compatible images format. data[0].url contains a time-limited URL to your generated image (valid for 24 hours). To get raw bytes instead, set "response_format": "b64_json" — the image arrives as a base64-encoded string in data[0].b64_json.
Curl equivalent:
curl -s -X POST https://genrelay.ai/v1/images/generations \
-H "Authorization: Bearer YOUR_GENRELAY_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "nano-banana-2",
"prompt": "Minimalist geometric logo, blue and white, clean vector style",
"size": "1024x1024",
"n": 1
}' | jq -r '.data[0].url'
What Parameters Does Nano Banana 2 Support?
| Parameter | Type | Options | Default | Notes |
|---|---|---|---|---|
model |
string | "nano-banana-2" |
— | Required |
prompt |
string | up to 4096 chars | — | Required |
size |
string | "1024x1024" (1K), "4096x4096" (4K) |
"1024x1024" |
Higher resolution = higher cost |
n |
integer | 1–4 | 1 | Number of images per request |
response_format |
string | "url" / "b64_json" |
"url" |
Delivery format |
Resolution guidance: Use 1K ($0.020) for web images, thumbnails, social previews, and UI assets. Use 4K ($0.036) when you need print-quality output, or when downstream workflows require a large canvas to crop from. Generating at 4K then downscaling for web costs 80% more per image — only do it when you need that resolution floor.
Prompt guidance: Nano Banana 2 responds well to specific, compositional prompts. Instead of "a chair," try "a mid-century modern wooden chair with leather cushion, white studio background, three-quarter view, soft fill lighting." Include subject, environment, lighting, and angle in that order for the most consistent output.
How Do I Generate Multiple Images in Parallel?
For bulk generation, concurrent requests outperform sequential ones by roughly the degree of concurrency you can sustain. Here's a thread-pool approach using Python's concurrent.futures:
import requests
from concurrent.futures import ThreadPoolExecutor, as_completed
API_KEY = "YOUR_GENRELAY_KEY"
ENDPOINT = "https://genrelay.ai/v1/images/generations"
def generate(prompt: str, size: str = "1024x1024") -> dict:
resp = requests.post(
ENDPOINT,
headers={"Authorization": f"Bearer {API_KEY}"},
json={"model": "nano-banana-2", "prompt": prompt, "size": size, "n": 1},
timeout=60,
)
resp.raise_for_status()
return {"prompt": prompt, "url": resp.json()["data"][0]["url"]}
prompts = [
"Red canvas sneaker, side view, white background, product photography",
"Blue trail running shoe, angled front view, clean studio shot",
"Black leather Oxford, top-down view, dark wood surface",
"White minimalist boot, neutral background, natural lighting",
]
results = []
with ThreadPoolExecutor(max_workers=4) as pool:
futures = {pool.submit(generate, p): p for p in prompts}
for future in as_completed(futures):
try:
results.append(future.result())
print(f"✓ {results[-1]['url'][:60]}...")
except requests.HTTPError as e:
print(f"✗ Failed: {e}")
print(f"\nGenerated {len(results)} images at ${len(results) * 0.020:.3f} total")
At $0.020 per image, generating 1,000 product images costs $20. A catalog of 50,000 images runs $1,000 — an order of magnitude below managed image creation services.
How Should I Handle Errors and Retries?
The GenRelay API returns standard HTTP error codes. Structure your retry logic around these cases:
- 429 Too Many Requests: Back off and retry. Use exponential backoff starting at 1 second.
- 500/503: Transient server errors. Retry up to 3 times before surfacing the failure.
- 400 Bad Request: Usually a prompt or parameter issue. Don't retry without changing the request.
import time
def generate_with_retry(prompt: str, max_retries: int = 3) -> str:
for attempt in range(max_retries):
try:
resp = requests.post(
ENDPOINT,
headers={"Authorization": f"Bearer {API_KEY}"},
json={"model": "nano-banana-2", "prompt": prompt, "n": 1},
timeout=60,
)
if resp.status_code == 429:
wait = 2 ** attempt
time.sleep(wait)
continue
resp.raise_for_status()
return resp.json()["data"][0]["url"]
except requests.RequestException as e:
if attempt == max_retries - 1:
raise
time.sleep(2 ** attempt)
Frequently Asked Questions
Does Nano Banana 2 support image editing or inpainting?
No. Nano Banana 2 is a text-to-image generation model — it generates from scratch based on a prompt. If you need to edit an existing image (fill regions, remove objects, adjust backgrounds), use GPT-image-2 via GenRelay, which supports mask-based inpainting.
What's the maximum prompt length for Nano Banana 2?
Up to 4,096 characters. Longer prompts don't always produce better results — a focused 100-word prompt with specific visual details typically outperforms a 500-word description with competing directives.
Do generated image URLs expire?
Yes. URLs returned in the "url" response format expire after 24 hours. If your pipeline needs to store images long-term, download and re-host them, or use "response_format": "b64_json" to receive raw image bytes in the response.
What is the typical generation latency for Nano Banana 2?
Most 1K-resolution requests complete in 5–15 seconds. 4K requests take longer — plan for 20–40 seconds depending on load. Set an HTTP timeout of at least 60 seconds to avoid premature cancellation during peak periods.
Can I use Nano Banana 2 for NSFW content?
GenRelay's content policy prohibits explicit content across all image models. Prompts that violate content guidelines return a 400 error with a policy message.
Practical Cost Planning
At $0.020 per 1K image:
| Volume/month | Monthly cost | Annual cost |
|---|---|---|
| 5,000 images | $100 | $1,200 |
| 20,000 images | $400 | $4,800 |
| 100,000 images | $2,000 | $24,000 |
If you mix resolutions — say, 80% at 1K and 20% at 4K — the blended rate for 100,000 images is approximately $2,320/month (80,000 × $0.020 + 20,000 × $0.036).
For dynamic requirements where some images warrant higher quality, route by use case: use Nano Banana 2 at 1K for thumbnails and previews, then only generate 4K when the user requests a download-quality version.
What to Build Next
Nano Banana 2's pricing and OpenAI-compatible API surface make it a straightforward drop-in for image generation in most backend stacks. Start with a single endpoint integration as shown above, then layer in:
- Model routing: default to Nano Banana 2, escalate to Nano Banana Pro for prompts with complex compositions or when previous output scores poorly in your quality pipeline.
- Caching: for template-based prompts with small variation, cache results by prompt hash — re-generating identical prompts wastes budget.
- Async queue: for batch jobs exceeding 100 images, decouple submission from retrieval to avoid blocking on long-running concurrent requests.
GenRelay's unified API means switching between Nano Banana 2 and any other image model is a one-parameter change. Explore all available image models to find the right tier for each workload.