> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dreamto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini 3.1 Flash Image

> Nano Banana 2: the Gemini image model that brings high-fidelity generation and faster advanced editing to the Flash tier, up to 4K.

`gemini-3.1-flash-image` (Nano Banana 2) is Google's Gemini model for image generation and editing. It brings high-fidelity generation and faster advanced editing to the Flash tier, with richer world knowledge, stricter instruction following, more accurate text rendering and in-image translation. It covers text-to-image, conversational multi-turn editing and multi-image composition at 1K / 2K / 4K, including extreme aspect ratios such as 1:4, 4:1, 1:8 and 8:1.

## Setup

| | Google | DreamTo |
| - | - | - |
| Base URL | `https://generativelanguage.googleapis.com` | `https://api.dreamto.ai` |
| API Key | Google AI Studio key | API Key from the DreamTo console, in the `x-goog-api-key` or `Authorization: Bearer` header |

## Endpoints

| Endpoint | Purpose |
| - | - |
| [`POST /v1beta/models/gemini-3.1-flash-image:generateContent`](https://docs.dreamto.ai/en/api-reference/gemini-3-1-flash-image/generate-content) | Generate content |

## Parameters

| Field | Values |
| - | - |
| `contents[].parts[].text` | The prompt: what to generate or change |
| `contents[].parts[].inlineData.data` | Reference image as Base64 (`mimeType` `image/png` / `image/jpeg` / `image/webp` / `image/heic` / `image/heif`); Google recommends up to 10 object images plus 4 character images |
| `contents[].parts[].fileData.fileUri` | Reference image as a public `https` link |
| `generationConfig.imageConfig.aspectRatio` | `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`; when omitted, `1:1` for text-to-image and the input image's ratio for edits |
| `generationConfig.imageConfig.imageSize` | `1K` (default) / `2K` / `4K`, uppercase `K`; the official 512px (0.5K) size is not supported yet |
| `generationConfig.responseModalities` | `["TEXT", "IMAGE"]` (default, text and images) or `["IMAGE"]` (images only) |

### Official parameters not supported yet

They return 400; the model is not called and nothing is charged.

| Parameter | Note |
| - | - |
| `systemInstruction` | System instructions are not supported yet; put them in the prompt |
| `safetySettings` | Custom safety thresholds are not supported yet; the defaults apply |
| `tools` | Grounding with Google Search (`google_search`) is not supported yet |

## Pricing

Billed at the model price shown in the console. Invalid requests and failed generations are not charged.

## Quick start

`$DREAMTO_API_KEY` is your API Key.

```bash cURL theme={null}
curl -X POST "https://api.dreamto.ai/v1beta/models/gemini-3.1-flash-image:generateContent" \
  -H "Authorization: Bearer $DREAMTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "An elegant dessert in a fancy banana-themed restaurant, soft lighting, food photography"
          }
        ]
      }
    ],
    "generationConfig": {
      "responseModalities": [
        "TEXT",
        "IMAGE"
      ],
      "imageConfig": {
        "aspectRatio": "16:9",
        "imageSize": "2K"
      }
    }
  }'
```

```python Python theme={null}
import base64
import os

import requests

URL = "https://api.dreamto.ai/v1beta/models/gemini-3.1-flash-image:generateContent"
HEADERS = {"x-goog-api-key": os.environ["DREAMTO_API_KEY"]}

payload = {
    "contents": [
        {
            "role": "user",
            "parts": [
                {
                    "text": "An elegant dessert in a fancy banana-themed restaurant, soft lighting, food photography"
                }
            ]
        }
    ],
    "generationConfig": {
        "responseModalities": [
            "TEXT",
            "IMAGE"
        ],
        "imageConfig": {
            "aspectRatio": "16:9",
            "imageSize": "2K"
        }
    }
}

response = requests.post(URL, headers=HEADERS, json=payload, timeout=300).json()
for part in response["candidates"][0]["content"]["parts"]:
    if "inlineData" in part:
        with open("output.png", "wb") as f:
            f.write(base64.b64decode(part["inlineData"]["data"]))
    elif "text" in part:
        print(part["text"])
```

## Notes

* This page covers `generateContent` only; the Batch API and `files/...` references from Files API uploads are not supported yet.
* Send reference images as Base64 in `inlineData`, or as a public `https` link in `fileData.fileUri`.
* Errors use the DreamTo error envelope (see the error examples) rather than Google's `status` envelope.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.