# Image Generation (OpenAI Protocol)

## 1.Overview

A text-to-image/image-to-image model launched by Google.

{% hint style="success" %}
This API is compatible with the OpenAI interface format.
{% endhint %}

**Model List:**

* `gemini-2.5-flash-image` (Nano-Banana)
* `gemini-3-pro-image-preview` (Nano-Banana-Pro)
* `gemini-3.1-flash-image-preview` (Nano-Banana-2)

{% hint style="warning" %}
This is a multimodal model. The description must explicitly include the scene to be drawn or explicitly request image generation. Simple words or phrases may not produce image output.
{% endhint %}

## 2. Request Description

* **Request Method**: `POST`
* **Request URL**:

  > `https://gateway.theturbo.ai/v1/images/generations`

***

## 3. Request Parameters

### 3.1 Header Parameters

| Parameter Name  | Type   | Required | Description                                                | Example                |
| --------------- | ------ | -------- | ---------------------------------------------------------- | ---------------------- |
| `Content-Type`  | string | Yes      | Set the request header type, must be `application/json`    | `application/json`     |
| `Accept`        | string | Yes      | Set the response type, recommended as `application/json`   | `application/json`     |
| `Authorization` | string | Yes      | API\_KEY for authentication, format `Bearer $YOUR_API_KEY` | `Bearer $YOUR_API_KEY` |

### 3.2 Body Parameters (application/json)

| Parameter Name | Type   | Required | Description                                                                                                                                                                                                                        | Example (Default)        |
| -------------- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
| **model**      | string | Yes      | The model ID to use. See the available versions listed above, such as `gemini-2.5-flash-image`.                                                                                                                                    | `gemini-2.5-flash-image` |
| **prompt**     | string | Yes      | A text description of the desired image. (This is a multimodal model. The description must explicitly include the scene to be drawn or explicitly request image generation. Simple words or phrases may not produce image output.) | `A cute baby sea otter`  |
| aspect\_ratio  | string | No       | The aspect ratio of the image to generate. Supported aspect ratios: `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, or `21:9`.                                                                                    |                          |
| image\_size    | string | No       | Specify the size of the generated image. Supported values are 1K, 2K, 4K.                                                                                                                                                          | `1K`                     |

## 4.Request Examples

{% tabs %}
{% tab title="HTTP" %}

```http
POST /v1/images/generations
Content-Type: application/json
Accept: application/json
Authorization: Bearer $YOUR_API_KEY

{
	"model": "gemini-2.5-flash-image",
	"prompt": "A cute baby sea otter",
	"aspect_ratio": "1:1"
}
```

{% endtab %}

{% tab title="Shell" %}

```sh
curl https://gateway.theturbo.ai/v1/images/generations \
	-H "Content-Type: application/json" \
	-H "Accept: application/json" \
	-H "Authorization: Bearer $YOUR_API_KEY" \
	-d '{
    "model": "gemini-2.5-flash-image",
    "prompt": "A cute baby sea otter",
    "aspect_ratio": "1:1"
}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"context"
	"encoding/base64"
	"fmt"
	"os"

	"github.com/openai/openai-go"
	"github.com/openai/openai-go/option"
)

func main() {

	apiKey := "sk-123456789012345678901234567890123456789012345678"
	exampleFilePath := "example.png"

	client := openai.NewClient(
		option.WithAPIKey(apiKey),
		option.WithBaseURL("https://gateway.theturbo.ai/v1"),
	)

	resp, err := client.Images.Generate(
		context.Background(),
		openai.ImageGenerateParams{
			Model:          "gemini-2.5-flash-image",
			Prompt:         "A cute baby sea otter",
			ResponseFormat: "b64_json",
		},
		option.WithJSONSet("aspect_ratio", "1:1"),
	)

	if err != nil {
		fmt.Println("error:", err)
		return
	}

	if len(resp.Data) == 0 || resp.Data[0].B64JSON == "" {
		fmt.Println("error: empty b64_json")
		return
	}

	imageData, err := base64.StdEncoding.DecodeString(resp.Data[0].B64JSON)
	if err != nil {
		fmt.Println("error:", err)
		return
	}

	if err := os.WriteFile(exampleFilePath, imageData, 0644); err != nil {
		fmt.Println("error:", err)
		return
	}

	fmt.Println("success to write to file", exampleFilePath)
}

```

{% endtab %}

{% tab title="Python" %}

```python
#!/usr/bin/env python3

import base64
from openai import OpenAI

def main():
    api_key = "sk-123456789012345678901234567890123456789012345678"
    example_file_path = "example.png"

    client = OpenAI(
        api_key=api_key,
        base_url="https://gateway.theturbo.ai/v1"
    )

    response = client.images.generate(
        model="gemini-2.5-flash-image",
        prompt="A cute baby sea otter",
        response_format="b64_json",
        extra_body={"aspect_ratio": "1:1"}
    )

    if not response.data or not response.data[0].b64_json:
        print("error: empty b64_json")
        return

    image_data = base64.b64decode(response.data[0].b64_json)

    with open(example_file_path, "wb") as f:
        f.write(image_data)

    print("success to write to file", example_file_path)

if __name__ == "__main__":
    main()

```

{% endtab %}
{% endtabs %}

## 5.Response Example

```json
{
	"created": 1589478378,
	"data": [
		{
			"b64_json": "..."
		}
	]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/api-reference/compute/aig/image-generation/nano-banana/nano-banana-image-openai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
