# **Nano-banana Image Generation API**

#### [Download this document as MD file](https://beeroute.ai/doc/coding/nano-banana.md)

**Endpoint Path**: `POST /v1/images/generations`

**Recommended Models**:

`nano-banana-2.1` (latest, based on Gemini 3.6 Flash: 1K–4K output, up to 14 reference images, about half the price of the previous generation)

`nano-banana-pro` (highest quality, based on Gemini 3 Pro Image: best for 4K posters and text-heavy images)

Older models (`nano-banana`, `nano-banana-2`, `nano-banana-2-lite`) can still be called for existing integrations; new projects should use the two models above.

**Note: Generated image URLs are temporary links (valid for 2 hours). Please save important works locally.**

---

### **Model Comparison**
| Feature | `nano-banana-2.1` | `nano-banana-pro` |
|---------|-------------------|-------------------|
| **Best for** | Fast, low-cost generation and editing | Highest quality, 4K, text rendering |
| **Supported Endpoint** | Image generation endpoint | Image generation endpoint |
| **Return Format** | URL or Base64 | URL or Base64 |
| **Aspect Ratio Setting** | ✅ Supported | ✅ Supported |
| **Image Size Setting** | ✅ Supported (1K/2K/4K) | ✅ Supported (1K/2K/4K) |
| **Native Web Access** | ✅ Supported | ✅ Supported |
| **Image-to-Image** | ✅ Supported (up to 14 images) | ✅ Supported |
| **Charge on Failure** | ✅ No charge | ✅ No charge |
| **Compatible Format** | DALL·E format | DALL·E format |

To call Google's native Gemini image API instead, see [Gemini Native (generateContent)](coding/gemini.md).

---

### **Request Parameters**

#### **Header**
| Parameter       | Type   | Required | Default              | Description              |
|----------------|--------|------|----------------------|--------------------------|
| `Authorization`| string | ✅   | `Bearer {{YOUR_API_KEY}}` | API authentication token |
| `Content-Type` | string | ✅   | `application/json`   | Request body type        |

#### **Body (`application/json`)**
| Parameter         | Type             | Required | Default  | Description                                                          |
|-------------------|------------------|------|----------|----------------------------------------------------------------------|
| `model`           | string           | ✅   | -        | Model name: `nano-banana-2.1` or `nano-banana-pro` |
| `prompt`          | string           | ✅   | -        | Image description text (supports both Chinese and English)           |
| `aspect_ratio`    | enum[string]     | ✅   | `auto`   | Image aspect ratio: `auto`, `1:1`, `4:3`, `3:4`, `16:9`, `9:16`, `2:3`, `3:2`, `4:5`, `5:4`, `21:9` |
| `response_format` | string           | ❌   | `url`    | Return format: `url` or `b64_json`                                   |
| `image`           | array[string]    | ❌   | -        | **Image-to-image** reference image list (URL or Base64), one or more images |
| `image_size`      | enum[string]     | ❌   | `1K`     | Output size: `1K`, `2K`, `4K` |
| `search`          | boolean          | ❌   | `false`  | Whether to enable native web access |

---

## 📌 Usage Scenario Examples

---

## 1. Text-to-Image

> Generate an image using only a text prompt, without passing the `image` parameter.

### 1.1 Basic Text-to-Image

#### JSON Body
```json
{
    "model": "nano-banana-2.1",
    "prompt": "An orange cat lying on a windowsill basking in the sun, with cherry blossoms in full bloom outside the window in spring",
    "aspect_ratio": "16:9"
}
```

#### cURL
```bash
curl -X POST 'https://beeroute.ai/v1/images/generations' \
  -H 'Authorization: Bearer {{YOUR_API_KEY}}' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "nano-banana-2.1",
    "prompt": "An orange cat lying on a windowsill basking in the sun, with cherry blossoms in full bloom outside the window in spring",
    "aspect_ratio": "16:9"
}'
```

---

### 1.2 High-Definition Text-to-Image (4K Quality)

#### JSON Body
```json
{
    "model": "nano-banana-pro",
    "prompt": "A cyberpunk-style futuristic city at night, neon lights reflected on rain-soaked streets, 4K ultra HD",
    "aspect_ratio": "21:9",
    "image_size": "4K"
}
```

#### cURL
```bash
curl -X POST 'https://beeroute.ai/v1/images/generations' \
  -H 'Authorization: Bearer {{YOUR_API_KEY}}' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "nano-banana-pro",
    "prompt": "A cyberpunk-style futuristic city at night, neon lights reflected on rain-soaked streets, 4K ultra HD",
    "aspect_ratio": "21:9",
    "image_size": "4K"
}'
```

---

### 1.3 Web-Connected Text-to-Image (Real-Time Information)

> After enabling `search`, the model can fetch real-time web information to assist generation.

#### JSON Body
```json
{
    "model": "nano-banana-2.1",
    "prompt": "Generate a promotional image of the latest 2025 Porsche 911 Turbo S, set on a race track",
    "aspect_ratio": "16:9",
    "image_size": "2K",
    "search": true
}
```

#### cURL
```bash
curl -X POST 'https://beeroute.ai/v1/images/generations' \
  -H 'Authorization: Bearer {{YOUR_API_KEY}}' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "nano-banana-2.1",
    "prompt": "Generate a promotional image of the latest 2025 Porsche 911 Turbo S, set on a race track",
    "aspect_ratio": "16:9",
    "image_size": "2K",
    "search": true
}'
```

---

### 1.4 Returning Base64 Format

#### JSON Body
```json
{
    "model": "nano-banana-2.1",
    "prompt": "Watercolor-style sunrise over Mount Fuji, with its reflection on the lake in the foreground",
    "aspect_ratio": "3:2",
    "response_format": "b64_json"
}
```
---

## 2. Image-to-Image

> Pass the `image` parameter (the reference image's URL or Base64), and combine it with a prompt to perform style transfer, editing, extension, and other operations on the image.

### 2.1 Image-to-Image — Passing an Image URL

#### JSON Body
```json
{
    "model": "nano-banana-2.1",
    "prompt": "Convert this photo into Studio Ghibli animation style, keeping the original composition while making the colors warmer and brighter",
    "aspect_ratio": "auto",
    "image": [
        "https://example.com/my-photo.jpg"
    ]
}
```

#### cURL
```bash
curl -X POST 'https://beeroute.ai/v1/images/generations' \
  -H 'Authorization: Bearer {{YOUR_API_KEY}}' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "nano-banana-2.1",
    "prompt": "Convert this photo into Studio Ghibli animation style, keeping the original composition while making the colors warmer and brighter",
    "aspect_ratio": "auto",
    "image": [
        "https://example.com/my-photo.jpg"
    ]
}'
```
---

### 2.2 Image-to-Image — Passing a Base64 Image

#### JSON Body Example (Base64 shown truncated)
```json
{
    "model": "nano-banana-2.1",
    "prompt": "Turn this portrait photo into a cyberpunk-style illustration with neon lighting effects",
    "aspect_ratio": "1:1",
    "image": [
        "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA..."
    ]
}
```

---

### 2.3 Image-to-Image — Multi-Image Reference Fusion

> Pass multiple reference images, and the model will create based on a comprehensive reference of all images.

#### JSON Body
```json
{
    "model": "nano-banana-pro",
    "prompt": "Blend the person from the first image into the scene of the second image, keeping it natural and harmonious with consistent lighting",
    "aspect_ratio": "4:3",
    "image_size": "2K",
    "image": [
        "https://example.com/person.jpg",
        "https://example.com/background.jpg"
    ]
}
```

#### cURL
```bash
curl -X POST 'https://beeroute.ai/v1/images/generations' \
  -H 'Authorization: Bearer {{YOUR_API_KEY}}' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "nano-banana-pro",
    "prompt": "Blend the person from the first image into the scene of the second image, keeping it natural and harmonious with consistent lighting",
    "aspect_ratio": "4:3",
    "image_size": "2K",
    "image": [
        "https://example.com/person.jpg",
        "https://example.com/background.jpg"
    ]
}'
```

---

### 2.4 Image-to-Image — High-Definition Image Editing

#### JSON Body
```json
{
    "model": "nano-banana-2.1",
    "prompt": "Add a vivid rainbow to this landscape photo and shift the sky to warm sunset tones",
    "aspect_ratio": "16:9",
    "image_size": "4K",
    "image": [
        "https://example.com/landscape.jpg"
    ]
}
```
---

## 3. Response Format

### Success Response (HTTP 200)

#### Returning URL Format (default)
```json
{
    "data": [
        {
            "url": "https://example.com/generated_image.png"
        }
    ]
}
```

#### Returning Base64 Format
```json
{
    "data": [
        {
            "b64_json": "/9j/4AAQSkZJRgABAQAAAQABAAD..."
        }
    ]
}
```

---

## 4. Common Scenarios Quick Reference

| Scenario | Recommended Model | Key Parameters | Prompt Example |
|------|----------|----------|-------------|
| **Basic Text-to-Image** | `nano-banana-2.1` | `aspect_ratio` | `"A corgi running on the grass"` |
| **4K Poster** | `nano-banana-pro` | `image_size: "4K"` | `"Cinematic sci-fi poster, space station scene"` |
| **Style Transfer** | `nano-banana-2.1` | `image: [url]` | `"Convert to oil painting style"` |
| **Image Editing** | `nano-banana-pro` | `image: [url]`, `image_size` | `"Remove the background and replace it with a beach"` |
| **Multi-Image Fusion** | `nano-banana-pro` | `image: [url1, url2]` | `"Combine the two images into one"` |
| **Web-Connected Generation** | `nano-banana-2.1` | `search: true` | `"Concept design of the latest 2025 iPhone"` |
| **Phone Wallpaper** | `nano-banana-2.1` | `aspect_ratio: "9:16"` | `"Aurora and starry sky wallpaper, dreamy purple tones"` |
| **Social Cover** | `nano-banana-2.1` | `aspect_ratio: "16:9"`, `image_size: "2K"` | `"Minimalist tech-style profile cover"` |

---

## 5. Key Notes

1. **Image Link Validity**: The returned URL is a temporary link that **expires after 2 hours**. Please download and save it promptly.
2. **No Charge on Failure**: No quota is deducted when generation fails.
3. **Image-to-Image `image` Parameter**: Supports passing **image URLs** or **Base64 strings**, which can be mixed, with one or more images.
4. `image_size`: `1K`, `2K`, or `4K` (uppercase `K`).
5. `search`: set to `true` to let the model use real-time web information.
6. **Prompt Tips**: The more detailed the description, the better the generated result; mixed Chinese-English prompts are supported.
