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

# Nano Banana

参数及使用方式已对齐官方，详细参数可直接参考官方文档。

## 调用方式

* `https://{api_domain}/gemini/v1/models/{model}:generateContent`
* `https://{api_domain}/gemini/v1beta/models/{model}:generateContent`

BaseURL：

* `https://{api_domain}/gemini`

## 支持模型

* `gemini-3.1-flash-lite-image`
* `gemini-3.1-flash-image`
* `gemini-3-pro-image`
* `gemini-2.5-flash-image`
* `gemini-3.1-flash-lite-image-as`
* `gemini-3.1-flash-image-as`
* `gemini-3-pro-image-as`
* `gemini-2.5-flash-image-as`

## REST API

请求示例（详细 API 使用参考官方即可 [https://ai.google.dev/gemini-api/docs/image-generation）](https://ai.google.dev/gemini-api/docs/image-generation）)

### 文生图

```bash theme={null}
curl -X POST 'https://{api_domain}/gemini/v1/models/gemini-2.5-flash-image:generateContent' \
    -H 'Authorization: Bearer apikey' \
    -H 'Content-Type: application/json' \
    -d '{
      "contents": [{
        "role": "user",
        "parts": [{"text": "Generate an image of a cute cat playing with yarn"}]
      }],
      "generationConfig": {
        "responseModalities": ["IMAGE"]
      }
    }'
```

### 图片编辑

```bash theme={null}
curl -X POST 'https://{api_domain}/gemini/v1/models/gemini-3-pro-image:generateContent' \
    -H 'Authorization: Bearer apikey' \
    -H 'Content-Type: application/json' \
    -d '{
      "contents": [{
        "role": "user",
        "parts": [
          {"text": "Add a party hat to this cat"},
          {
            "inlineData": {
              "mimeType": "image/jpeg",
              "data": "'"$(cat /path/to/image | base64 -w0)"'"
            }
          }
        ]
      }],
      "generationConfig": {
        "responseModalities": ["TEXT", "IMAGE"],
        "imageConfig": {
            "aspectRatio": "16:9",
            "imageSize": "2K"
        }
      }
    }'
```

## GenAI SDK

```python theme={null}
from google import genai
from google.genai import types

api_key = "{your-api-key}"

client = genai.Client(
    http_options=types.HttpOptions(
        base_url=f"https://{api_domain}/gemini",
        api_version="v1",
        headers={
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json",
        },
    ),
    api_key=api_key,
)

try:
    response = client.models.generate_content(
        model="gemini-2.5-flash-image",
        contents="Generate an image of a cute cat playing with yarn",
        config=types.GenerateContentConfig(
            response_modalities=["IMAGE"],
        ),
    )
except Exception as e:
    print(f"API request failed: {e}")
    exit(1)

# Extract the generated image
if not response.candidates:
    print("No candidates returned in the response.")
    exit(1)

for part in response.candidates[0].content.parts:
    if part.inline_data:
        try:
            data = part.inline_data.data
            if isinstance(data, str):
                import base64
                data = base64.b64decode(data)
            with open("output.png", "wb") as f:
                f.write(data)
            print("Image saved to output.png")
        except (OSError, base64.binascii.Error) as e:
            print(f"Failed to save image: {e}")
    elif part.text:
        print(part.text)
```

## 最佳实践

### 思考草稿图问题

* 默认参数 `responseModalities=["TEXT", "IMAGE"]`，此时生图概率性会生成 2 张图片，一张 1k 思考图、一张正式图。其中思考图按思考输出 Token 收费，正式图按正式输出 Token 收费。
* 需要设置 `responseModalities = ["IMAGE"]`，此时才仅生成正式图片。
