# Nano Banana 2 API (Gemini 3.1 Flash Image)

High-quality image generation using GET and POST requests. Supports Gemini 3.1 Flash (Nano Banana 2) and Gemini 2.5 Flash (Nano Banana).

## Example URLs

**Basic Generation (Gemini 3.1 Flash):**
```
/api/nanobanana/image/1024/1024?prompt=wizard+in+purple+robes+holding+crystal+staff+photorealistic
```

**Advanced Parameters (Aspect Ratio, Size, Negative Prompt):**
```
/api/nanobanana/image/1024/1024?prompt=fantasy+landscape&aspect_ratio=16:9&size=1K&negative_prompt=blurry,low+quality
```

**Search Grounding (Uses Google Search for facts):**
```
/api/nanobanana/image/1024/1024?prompt=The+new+Tesla+Bot+in+a+garden&grounding=true
```

## Endpoints

**Static Images (GET):**
- `/api/nanobanana/image/{width}/{height}?prompt=...`

**Advanced Generation (POST):**
- `POST /api/nanobanana/image` (supports file uploads, editing, composition - redirects to cached image URL)

## Size Guidelines

**Max Resolution:** 1024x1024. Use exact pixel dimensions in the URL path — aspect ratio and size class are derived automatically.

## GET/POST Parameters

- `prompt` (required): Text description of the image
- `negative_prompt`: Things to EXCLUDE from the image
- `grounding`: `true` to enable Google Search grounding (costs +1 credit)
- `seed`: Reproducible results
- `base_image_url`: URL to base image for editing
- `reference_images_urls`: Comma-separated URLs for composition (up to 14)

## POST Operations

### Basic Generation
```javascript
{
  prompt: "professional headshot business woman studio lighting",
  width: 512,
  height: 512
}
```

### Image Editing (presence of base_image triggers edit mode)
```javascript
{
  prompt: "change the background to a modern office",
  base_image: File, // or base_image_base64 or base_image_url
  strength: 0.7
}
```

### Multi-Image Composition
```javascript
{
  prompt: "character consistency across scenes",
  reference_images: [File, File] // up to 14 reference images
}
```

## Prompt Tips

**Good Structure:** `[Subject] + [Action/Pose] + [Setting] + [Style/Mood] + [Technical details]`

Examples:
- `professional businesswoman smiling confidently modern office natural lighting`
- `abstract geometric composition vibrant blue gold colors minimalist style`
- `cozy living room fireplace warm lighting evening atmosphere`