# gemini-2.5-flash-image (nano banana)

This document describes the input and output parameters of the `gemini-2.5-flash-image` model API, helping you understand the meaning of fields during API usage.

---

This document only describes part of the fields used. For detailed fields of the Gemini API, see the [Gemini official documentation](https://ai.google.dev/gemini-api/docs/image-generation?hl=en).

## Request Parameters

### Request Body

| Field Name                             | Type   | Required | Default Value      | Description                             |
| -------------------------------------- | ------ | -------- | ------------------ | --------------------------------------- |
| contents                               | array  | Required | -                  | Content of the request, containing one or more parts. |
| contents.role                          | string | Required | "user"             | Role of the content, fixed as "user".   |
| contents.parts                         | array  | Required | -                  | Specific parts of the content.          |
| contents.parts.text                    | string | Optional | -                  | Prompt text.                            |
| contents.parts.inlineData              | object | Optional | -                  | Inline data (e.g., images).             |
| contents.parts.inlineData.mimeType     | string | Optional | -                  | MIME type of the data.                  |
| contents.parts.inlineData.data         | string | Optional | -                  | Base64 encoded data.                    |
| contents.parts.fileData                | object | Optional | -                  | File data, supports snake_case: file_data. |
| contents.parts.fileData.mimeType       | string | Optional | -                  | MIME type of the file.                  |
| contents.parts.fileData.fileUri        | string | Optional | -                  | URI of the file.                        |
| generationConfig                       | object | Optional | -                  | Generation configuration.               |
| generationConfig.responseModalities    | array  | Optional | ["TEXT", "IMAGE"]  | Expected response modalities, can be text or image. |

## Response Parameters

| Field Name                                       | Type      | Description                                 |
| ------------------------------------------------ | --------- | ------------------------------------------- |
| candidates                                       | `array`   | List of returned candidate contents.        |
| candidates.content                               | `object`  | Candidate content.                          |
| candidates.content.parts                         | `array`   | Specific parts of the content, may include text and image data. |
| candidates.content.parts.text                    | `string`  | Text description returned by the model.     |
| candidates.content.parts.inlineData              | `object`  | Inline image data.                          |
| candidates.content.parts.inlineData.data         | `string`  | Base64 encoded image data.                  |
| candidates.content.parts.inlineData.mimeType     | `string`  | MIME type of the data, such as "image/png". |
| candidates.content.role                          | `string`  | Role of the content, here it is "model".    |
| candidates.finishReason                          | `string`  | Reason for generation ending, e.g., "STOP". |
| usageMetadata                                    | `object`  | Metadata of token usage.                    |
| usageMetadata.candidatesTokenCount               | `integer` | Tokens consumed by candidate content.       |
| usageMetadata.promptTokenCount                   | `integer` | Tokens consumed by prompts.                 |
| usageMetadata.totalTokenCount                    | `integer` | Total tokens consumed.                      |
| error                                            | `Object`  | Error information object.                   |
| error.code                                       | `string`  | Error code.                                 |
| error.message                                    | `string`  | Error message.                              |
| error.param                                      | `string`  | Request id.                                 |

## Examples

### Gemini Compatible Interface
We provide compatibility for the gemini `{xxx}/v1beat/models` interface. You can directly use the official SDK to call this, for example [python-genai](https://github.com/googleapis/python-genai).

`POST https://api-us-ca.umodelverse.ai/v1beta/models/gemini-2.5-flash-image:generateContent`

#### Image Generation (Text to Image)

> ⚠️ Note: You must add responseModalities: ["TEXT", "IMAGE"] in the configuration. These models do not support image-only output.

<!-- tabs:start -->

##### ** curl **

```bash
curl --location 'https://api-us-ca.umodelverse.ai/v1beta/models/gemini-2.5-flash-image:generateContent' \
--header "x-goog-api-key: $MODELVERSE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "contents": [
        {
            "role": "user",
            "parts": [
                {
                    "text": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"
                }
            ]
        }
    ],
    "generationConfig": {
        "responseModalities": [
            "TEXT",
            "IMAGE"
        ]
    }
}' | jq -r '.candidates[0].content.parts[1].inlineData.data' \
| base64 -d > modelverse_generated_image.png
```

##### ** python **

```python
from google import genai
from google.genai import types
from PIL import Image
from io import BytesIO
import os


client = genai.Client(
    api_key=os.getenv("Modelverse_API_KEY", "<UModelverse_API_KEY>"),  # Your API_KEY
    http_options=types.HttpOptions(
        base_url="https://api-us-ca.umodelverse.ai"
    ),
)

contents = [
    {
        "text": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme.",
    },
]

generation_config = types.GenerationConfig(
    response_modalities=["text", "image"],
)

response = client.models.generate_content(
    model="gemini-2.5-flash-image",
    contents=contents,
    config={
        "response_modalities": ["text", "image"],
    },
)

for part in response.candidates[0].content.parts:
    if part.text is not None:
        print(part.text)
    elif part.inline_data is not None:
        image = Image.open(BytesIO(part.inline_data.data))
        image.save("modelverse_generated_image.png")
)

```

<!-- tabs:end -->

#### Image Editing (Text and Image to Image)

<!-- tabs:start -->

##### ** curl **

```bash
cat <<EOF | curl -X POST \
  --header "Authorization: Bearer ${MODELVERSE_API_KEY}" \
  --header "Content-Type: application/json" \
  --data @- \
  https://api-us-ca.umodelverse.ai/v1beta/models/gemini-2.5-flash-image:generateContent | jq -r '.candidates[0].content.parts[] | select(.inlineData) | .inlineData.data' | base64 --decode > modelverse_generated_image.png
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {"text": "Convert this photo to black and white, in a cartoonish style."},
        {
          "inlineData": {
            "mimeType": "image/jpeg",
            "data": "$(curl -s https://umodelverse-inference.cn-wlcb.ufileos.com/ucloud-maxcot.jpg | base64 | tr -d '\n')"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": ["TEXT", "IMAGE"]
  }
}
EOF
```

##### ** python **

```python
from google import genai
from google.genai import types
from PIL import Image
from io import BytesIO
import os

client = genai.Client(
    api_key=os.getenv("Modelverse_API_KEY", "<UModelverse_API_KEY>"),  # Your API_KEY
    http_options=types.HttpOptions(
        base_url="https://api-us-ca.umodelverse.ai"
    ),
)

response = client.models.generate_content(
    model="gemini-2.5-flash-image",
    contents=[
        types.Content(
            role="user",
            parts=[
                types.Part(
                    text="Convert this photo to black and white, in a cartoonish style."
                ),
                types.Part(
                    file_data=types.FileData(
                        mime_type="image/jpeg",
                        file_uri="https://umodelverse-inference.cn-wlcb.ufileos.com/ucloud-maxcot.jpg",
                    )
                ),
            ],
        )
    ],
    config=types.GenerateContentConfig(response_modalities=["TEXT", "IMAGE"]),
)

for part in response.candidates[0].content.parts:
    if part.text is not None:
        print(part.text)
    elif part.inline_data is not None:
        image = Image.open(BytesIO(part.inline_data.data))
        image.save("modelverse_generated_image.png")

```

<!-- tabs:end -->

### Response Example

```json
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "That sounds incredibly unique! Here's a picture of a nano banana dish in a fancy restaurant with a Gemini theme:\n\n"
          },
          {
            "inlineData": {
              "data": "xxx",
              "mimeType": "image/png"
            }
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "candidatesTokenCount": 1315,
    "candidatesTokensDetails": [
      {
        "modality": "IMAGE",
        "tokenCount": 1290
      },
      {
        "modality": "TEXT",
        "tokenCount": 25
      }
    ],
    "promptTokenCount": 16,
    "promptTokensDetails": [
      {
        "modality": "TEXT",
        "tokenCount": 16
      }
    ],
    "totalTokenCount": 1331,
    "trafficType": "ON_DEMAND"
  }
}
```

```json
{
  "error": {
    "message": "error_message",
    "type": "error_type",
    "param": "request_id",
    "code": "error_code"
  }
}
```