# Nano Banana 2 (nano-banana-2) Vendor: Google Model ID: `nano-banana-2` Base URL: `https://api.mulerouter.ai` Type: Inference API (async task-based) ## Description Next-generation image generation and editing model with 4K support, 14 aspect ratios, and web search grounding ## Variant: Image to Image Edit Endpoint: `POST /vendors/google/v1/nano-banana-2/edit` ### Input Schema The API accepts the following input parameters: - **`images`** (`list`, _required_): List of reference images for editing. Supports both image URLs and base64-encoded images. Base64 format: `data:image/png;base64,{base64_data}` Supported formats: JPEG, JPG, PNG, BMP, WEBP Max file size per image: 20MB Nano Banana 2 supports up to 14 reference images: - Up to 10 images of objects (high-fidelity preservation) - Up to 4 images of characters (character consistency) - Items: min: 1, max: 14 - **`prompt`** (`string`, _required_): Text prompt for image editing. Describe the desired change conversationally. For adding/removing elements: "Add a wizard hat on the cat's head" For inpainting: "Change only the blue sofa to a brown leather chesterfield" For style transfer: "Transform this photo into Van Gogh's Starry Night style" - **`resolution`** (`string`, _optional_): Output resolution preset. **Note:** Must use uppercase K (e.g. 1K, 2K, 4K). Lowercase will be rejected. - Options: `"1K"`, `"2K"`, `"4K"` - Default: `"1K"` - **`web_search`** (`boolean`, _optional_): Enable Google Search grounding for image editing. When enabled, the model can use Google Search (including Web Search and Image Search) to verify facts and generate imagery based on real-time data such as current weather, stock charts, recent events, or accurate depictions of real-world subjects. - Default: `false` - **`aspect_ratio`** (`string`, _optional_): Aspect ratio of the edited image (width:height). - Options: `"1: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"` - Default: `"1:1"` **Required Parameters Example**: ```json { "prompt": "", "images": [] } ``` **Full Example**: ```json { "images": [], "prompt": "", "resolution": "1K", "web_search": false, "aspect_ratio": "1:1" } ``` ## Variant: Text to Image Generation Endpoint: `POST /vendors/google/v1/nano-banana-2/generation` ### Input Schema The API accepts the following input parameters: - **`prompt`** (`string`, _required_): Text prompt for image generation. For best results, describe the scene narratively rather than listing keywords. Include details such as: - Subject (object, person, animal, scenery) - Style (photorealistic, illustration, sketch, etc.) - Lighting and mood - Camera angle and composition - Color palette Example: "A photorealistic close-up portrait of an elderly Japanese ceramicist with deep, sun-etched wrinkles and a warm, knowing smile. Captured with an 85mm portrait lens, resulting in soft bokeh." - **`resolution`** (`string`, _optional_): Output resolution preset. **Note:** Must use uppercase K (e.g. 1K, 2K, 4K). Lowercase will be rejected. - Options: `"1K"`, `"2K"`, `"4K"` - Default: `"1K"` - **`web_search`** (`boolean`, _optional_): Enable Google Search grounding for image generation. When enabled, the model can use Google Search (including Web Search and Image Search) to verify facts and generate imagery based on real-time data such as current weather, stock charts, recent events, or accurate depictions of real-world subjects. - Default: `false` - **`aspect_ratio`** (`string`, _optional_): Aspect ratio of the generated image (width:height). - Options: `"1: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"` - Default: `"1:1"` **Required Parameters Example**: ```json { "prompt": "" } ``` **Full Example**: ```json { "prompt": "", "resolution": "1K", "web_search": false, "aspect_ratio": "1:1" } ``` ## Variant: /vendors/google/v1/nano-banana-2/edit/{task_id} Endpoint: `POST /vendors/google/v1/nano-banana-2/edit/{task_id}` ## Variant: /vendors/google/v1/nano-banana-2/generation/{task_id} Endpoint: `POST /vendors/google/v1/nano-banana-2/generation/{task_id}` ## Usage (Async Task API) This model uses an async task-based workflow with two API calls: 1. **Submit a task** — `POST /v1/inference/nano-banana-2` to create a generation task 2. **Poll for result** — `GET /v1/inference/nano-banana-2/{task_id}` to check status and retrieve the result ### Step 1: Submit a Task #### cURL ```bash curl -X POST https://api.mulerouter.ai/vendors/google/v1/nano-banana-2/edit \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -d '{ "prompt": "Your prompt here" }' ``` #### Python ```python import requests API_KEY = "" ENDPOINT = "https://api.mulerouter.ai/vendors/google/v1/nano-banana-2/edit" response = requests.post( ENDPOINT, headers={ "Content-Type": "application/json", "Authorization": f"Bearer {API_KEY}" }, json={ "prompt": "Your prompt here" } ) result = response.json() task_id = result["task_info"]["id"] print(f"Task created: {task_id}") ``` #### Node.js / TypeScript ```typescript const API_KEY = ""; const ENDPOINT = "https://api.mulerouter.ai/vendors/google/v1/nano-banana-2/edit"; const response = await fetch(ENDPOINT, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${API_KEY}` }, body: JSON.stringify({ prompt: "Your prompt here" }) }); const result = await response.json(); const taskId = result.task_info.id; console.log("Task created:", taskId); ``` #### Submit Response (202) ```json { "task_info": { "id": "8e1e315e-b50d-4334-a231-be7d19a372f4", "status": "processing", "created_at": "2026-01-01T00:00:00.000Z" } } ``` ### Step 2: Poll for Result Use the task ID from Step 1 to poll the status endpoint until the task is completed. Endpoint: `GET /v1/inference/nano-banana-2/{task_id}` #### cURL ```bash curl -X GET https://api.mulerouter.ai/vendors/google/v1/nano-banana-2/edit/ \ -H "Authorization: Bearer " ``` #### Python ```python import time status_url = f"https://api.mulerouter.ai/vendors/google/v1/nano-banana-2/edit/{task_id}" while True: status = requests.get(status_url, headers={ "Authorization": f"Bearer {API_KEY}" }).json() task_status = status["task_info"]["status"] if task_status in ("completed", "succeeded"): print("Result:", status) break elif task_status == "failed": print("Task failed:", status) break time.sleep(5) ``` #### Node.js / TypeScript ```typescript const statusUrl = `https://api.mulerouter.ai/vendors/google/v1/nano-banana-2/edit/${taskId}`; while (true) { const statusRes = await fetch(statusUrl, { headers: { "Authorization": `Bearer ${API_KEY}` } }); const status = await statusRes.json(); const taskStatus = status.task_info.status; if (taskStatus === "completed" || taskStatus === "succeeded") { console.log("Result:", status); break; } else if (taskStatus === "failed") { console.log("Task failed:", status); break; } await new Promise(r => setTimeout(r, 5000)); } ``` ## Additional Resources ### Documentation - [Model Playground](https://www.mulerouter.ai/models/nano-banana-2) - [API Documentation](https://api.mulerouter.ai/docs/api-reference/endpoint/google/nano-banana-2) ### MuleRouter Platform - [Platform Documentation](https://www.mulerouter.ai/docs) - [API Keys Management](https://www.mulerouter.ai/app/api-keys)