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

# Gemini-2.5-Flash Official Image Generation

> Generate images using Google Gemini 2.5 Flash official direct-connect model, fast and efficient

> [!NOTE]
>
> **Note for users in mainland China:** Please use `https://toapis.cn` as the API endpoint (Base URL). Replace `https://toapis.com` with `https://toapis.cn` in the examples in this document.

* Direct connection to Google Vertex AI using the Gemini 2.5 Flash Image native API
* Select the `gemini-2.5-flash-image-official` model via the model parameter
* Nano Banana official alias: `nano-banana-official`
* Supports text-to-image and image-to-image generation
* Supports native generation parameters like temperature, topP, and maxOutputTokens
* Supports personGeneration and imageOutputOptions image configuration
* Supports safetySettings for content safety control
* Asynchronous task management with task ID for result querying

> [!WARNING]
>
> **Important Change**: For better performance and cost control, we no longer support passing base64 image data directly in `image_urls`. Please use the [Upload Image endpoint](https://docs.toapis.com/docs/en/api-reference/uploads/images.md) to upload images first, then use the returned URL in this API.

## Authorizations

**Authorization** `string` *required*

All endpoints require Bearer Token authentication

Get API Key: Visit the [API Key Management page](https://toapis.com/console/token) to obtain your API Key

Add to request headers:

```
Authorization: Bearer YOUR_API_KEY
```

## Body

**model** `string` *required* (default: gemini-2.5-flash-image-official)

Image generation model name

Example: `"gemini-2.5-flash-image-official"`

**prompt** `string` *required*

Text description for image generation

**size** `string`

Image aspect ratio

Supported formats:

* `1:1` - Square
* `3:2` / `2:3`
* `3:4` / `4:3`
* `4:5` / `5:4`
* `9:16` / `16:9`
* `21:9`

**n** `integer` (default: 1)

Number of images to generate

Fixed at 1

**image\_urls** `string[]`

Reference image URL array for image-to-image generation or editing

**⚠️ Only URL format is supported (base64 is no longer supported)**

* Publicly accessible image URLs (http\:// or https\://)
* Use the [Upload Image endpoint](https://docs.toapis.com/docs/en/api-reference/uploads/images.md) to upload local images and get URLs

**Limits:**

* Maximum 3 images
* Maximum file size per image: 10MB
* Supported formats: .jpeg, .jpg, .png, .webp

**metadata** `object`

Vertex AI native extension parameters

**Show metadata fields**

**temperature** `number`

Generation temperature, controls output randomness

Range: `0.0` - `2.0`, default `1.0`

**topP** `number`

Top-P sampling parameter

Range: `0.0` - `1.0`, default `0.95`

**maxOutputTokens** `integer`

Maximum output tokens

Default `32768`

**personGeneration** `string`

Person generation control

Options:

* `ALLOW_ALL` - Allow generating all people (including adults and children)
* `ALLOW_ADULT` - Allow generating adults only
* `ALLOW_NONE` - Disallow generating people

**imageOutputOptions** `object`

Image output format configuration

**imageOutputOptions fields**

**mimeType** `string`

Output image format

Options: `image/png`, `image/jpeg`, `image/webp`

**compressionQuality** `integer`

Compression quality (JPEG only)

**safetySettings** `array`

Safety settings array for content safety filtering

**safetySettings elements**

**category** `string`

Safety category

Options: `HARM_CATEGORY_HATE_SPEECH`, `HARM_CATEGORY_DANGEROUS_CONTENT`, `HARM_CATEGORY_SEXUALLY_EXPLICIT`, `HARM_CATEGORY_HARASSMENT`

**threshold** `string`

Filtering threshold

Options: `OFF`, `BLOCK_LOW_AND_ABOVE`, `BLOCK_MEDIUM_AND_ABOVE`, `BLOCK_ONLY_HIGH`

## Response

**id** `string`

Unique task identifier for querying task status

**object** `string`

Object type, always `generation.task`

**model** `string`

Model name used

**status** `string`

Task status

* `queued` - Queued for processing
* `in_progress` - Processing
* `completed` - Successfully completed
* `failed` - Failed

**progress** `integer`

Task progress percentage (0-100)

**created\_at** `integer`

Task creation timestamp (Unix timestamp)

**metadata** `object`

Task metadata

```bash cURL theme={null}
curl --request POST \
  --url https://toapis.com/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gemini-2.5-flash-image-official",
    "prompt": "A cat wearing an astronaut suit walking on the moon",
    "size": "1:1",
    "n": 1,
    "metadata": {
      "temperature": 1.0
    }
  }'
```

```python Python theme={null}
import requests

response = requests.post(
    "https://toapis.com/v1/images/generations",
    headers={
        "Authorization": "Bearer your-ToAPIs-key",
        "Content-Type": "application/json"
    },
    json={
        "model": "gemini-2.5-flash-image-official",
        "prompt": "A cat wearing an astronaut suit walking on the moon",
        "size": "1:1",
        "n": 1,
        "metadata": {
            "temperature": 1.0
        }
    }
)

task = response.json()
print(f"Task ID: {task['id']}")
print(f"Status: {task['status']}")
```

```javascript JavaScript theme={null}
const response = await fetch('https://toapis.com/v1/images/generations', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your-ToAPIs-key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    model: 'gemini-2.5-flash-image-official',
    prompt: 'A cat wearing an astronaut suit walking on the moon',
    size: '1:1',
    n: 1,
    metadata: {
      temperature: 1.0
    }
  })
});

const task = await response.json();
console.log(`Task ID: ${task.id}`);
console.log(`Status: ${task.status}`);
```

```json 200 theme={null}
{
  "id": "task_img_abc123def456",
  "object": "generation.task",
  "model": "gemini-2.5-flash-image-official",
  "status": "queued",
  "progress": 0,
  "created_at": 1703884800,
  "metadata": {}
}
```


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