# Gemini Nano Banana 2.1 图像生成

> 图像生成

传入文本提示词生成图片，或同时传入文本和内嵌图片进行编辑。响应包含候选内容和用量信息。
Nano Banana 2.1 不支持 `seed`、`topK`、`logprobs`、`temperature` 和 `topP` 参数。设置上述任一参数都会返回 API 错误。请从 generationConfig 中移除这些字段，并检查 SDK 或请求封装是否自动填入这些参数。

## 请求地址

`POST https://api.modelverse.cn/v1beta/models/gemini-nano-banana-2.1:generateContent`

## 请求体

## 响应

- **200** — 候选内容；检查 finishReason 和 promptFeedback 以确认是否生成图片。
- **400** — 请求参数错误。
Nano Banana 2.1 不支持 `seed`、`topK`、`logprobs`、`temperature` 和 `topP` 参数。设置上述任一参数都会返回 API 错误。请从 generationConfig 中移除这些字段，并检查 SDK 或请求封装是否自动填入这些参数。

- **default** — 错误响应。

## OpenAPI 定义

```json
{
  "openapi": "3.1.0",
  "x-language": "zh-CN",
  "info": {
    "title": "Gemini Nano Banana 2.1 图像生成与编辑 API",
    "version": "1.0.0",
    "description": "通过 ModelVerse Gemini 兼容接口调用 `gemini-nano-banana-2.1`，支持文本生成图片和图片编辑。\nNano Banana 2.1 不支持 `seed`、`topK`、`logprobs`、`temperature` 和 `topP` 参数。设置上述任一参数都会返回 API 错误。请从 generationConfig 中移除这些字段，并检查 SDK 或请求封装是否自动填入这些参数。\n官方规格：支持 1K、2K、4K 分辨率；不要沿用 Nano Banana 2 的 512 分辨率示例。每个提示最多输入 14 张图片，每张内嵌图片最大 7 MB。上下文窗口为 131,072 tokens，输出上限为 32,768 tokens。\n"
  },
  "externalDocs": {
    "description": "Google 官方模型文档",
    "url": "https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/nano-banana-2-1?hl=zh-cn"
  },
  "servers": [
    {
      "url": "https://api.modelverse.cn",
      "description": "ModelVerse API"
    }
  ],
  "tags": [
    {
      "name": "gemini-nano-banana-2.1",
      "description": "Gemini 兼容图片生成与编辑。"
    }
  ],
  "security": [
    {
      "geminiApiKeyAuth": []
    }
  ],
  "paths": {
    "/v1beta/models/gemini-nano-banana-2.1:generateContent": {
      "post": {
        "tags": [
          "gemini-nano-banana-2.1"
        ],
        "operationId": "generateGeminiNanoBanana21Content",
        "summary": "Gemini Nano Banana 2.1 图像生成",
        "description": "传入文本提示词生成图片，或同时传入文本和内嵌图片进行编辑。响应包含候选内容和用量信息。\nNano Banana 2.1 不支持 `seed`、`topK`、`logprobs`、`temperature` 和 `topP` 参数。设置上述任一参数都会返回 API 错误。请从 generationConfig 中移除这些字段，并检查 SDK 或请求封装是否自动填入这些参数。\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerateContentRequest"
              },
              "examples": {
                "textToImage": {
                  "summary": "1K 文生图",
                  "value": {
                    "contents": [
                      {
                        "role": "user",
                        "parts": [
                          {
                            "text": "Create a watercolor painting of a small orange cat in a garden."
                          }
                        ]
                      }
                    ],
                    "generationConfig": {
                      "responseModalities": [
                        "TEXT",
                        "IMAGE"
                      ],
                      "imageConfig": {
                        "aspectRatio": "1:1",
                        "imageSize": "1K"
                      }
                    }
                  }
                },
                "imageEditing": {
                  "summary": "2K 图片编辑（替换 Base64 占位数据）",
                  "value": {
                    "contents": [
                      {
                        "role": "user",
                        "parts": [
                          {
                            "text": "Turn this photo into a watercolor painting."
                          },
                          {
                            "inlineData": {
                              "mimeType": "image/jpeg",
                              "data": "<BASE64_IMAGE_DATA>"
                            }
                          }
                        ]
                      }
                    ],
                    "generationConfig": {
                      "responseModalities": [
                        "TEXT",
                        "IMAGE"
                      ],
                      "imageConfig": {
                        "aspectRatio": "1:1",
                        "imageSize": "2K"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "候选内容；检查 finishReason 和 promptFeedback 以确认是否生成图片。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerateContentResponse"
                },
                "examples": {
                  "generatedImage": {
                    "summary": "图片响应结构示意（图片数据已省略）",
                    "value": {
                      "candidates": [
                        {
                          "content": {
                            "role": "model",
                            "parts": [
                              {
                                "inlineData": {
                                  "mimeType": "image/png",
                                  "data": "<BASE64_IMAGE_DATA>"
                                }
                              }
                            ]
                          },
                          "finishReason": "STOP"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "请求参数错误。\nNano Banana 2.1 不支持 `seed`、`topK`、`logprobs`、`temperature` 和 `topP` 参数。设置上述任一参数都会返回 API 错误。请从 generationConfig 中移除这些字段，并检查 SDK 或请求封装是否自动填入这些参数。\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "default": {
            "description": "错误响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "geminiApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-goog-api-key",
        "description": "ModelVerse API Key"
      }
    },
    "schemas": {
      "GenerateContentRequest": {
        "type": "object",
        "required": [
          "contents"
        ],
        "properties": {
          "contents": {
            "type": "array",
            "minItems": 1,
            "description": "请求消息，包含文本或图片。",
            "items": {
              "$ref": "#/components/schemas/RequestContent"
            }
          },
          "generationConfig": {
            "$ref": "#/components/schemas/GenerationConfig"
          }
        }
      },
      "RequestContent": {
        "type": "object",
        "required": [
          "parts"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "user",
              "model"
            ],
            "description": "消息角色；单轮请求示例使用 user。"
          },
          "parts": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/RequestPart"
            }
          }
        }
      },
      "RequestPart": {
        "type": "object",
        "anyOf": [
          {
            "required": [
              "text"
            ]
          },
          {
            "required": [
              "inlineData"
            ]
          }
        ],
        "properties": {
          "text": {
            "type": "string",
            "description": "生成或编辑图片的提示词。"
          },
          "inlineData": {
            "$ref": "#/components/schemas/InputImage"
          }
        }
      },
      "InputImage": {
        "type": "object",
        "required": [
          "mimeType",
          "data"
        ],
        "properties": {
          "mimeType": {
            "type": "string",
            "enum": [
              "image/png",
              "image/jpeg",
              "image/webp",
              "image/heic",
              "image/heif"
            ],
            "description": "输入图片 MIME 类型。"
          },
          "data": {
            "type": "string",
            "description": "Base64 编码的图片数据，不含 data URI 前缀；单张内嵌图片最大 7 MB。"
          }
        }
      },
      "GenerationConfig": {
        "type": "object",
        "description": "Nano Banana 2.1 不支持 `seed`、`topK`、`logprobs`、`temperature` 和 `topP` 参数。设置上述任一参数都会返回 API 错误。请从 generationConfig 中移除这些字段，并检查 SDK 或请求封装是否自动填入这些参数。\n",
        "not": {
          "anyOf": [
            {
              "required": [
                "seed"
              ]
            },
            {
              "required": [
                "topK"
              ]
            },
            {
              "required": [
                "logprobs"
              ]
            },
            {
              "required": [
                "temperature"
              ]
            },
            {
              "required": [
                "topP"
              ]
            }
          ]
        },
        "properties": {
          "responseModalities": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "description": "期望的响应模态；示例使用 TEXT 和 IMAGE。",
            "items": {
              "type": "string",
              "enum": [
                "TEXT",
                "IMAGE"
              ]
            },
            "examples": [
              [
                "TEXT",
                "IMAGE"
              ]
            ]
          },
          "imageConfig": {
            "$ref": "#/components/schemas/ImageConfig"
          }
        }
      },
      "ImageConfig": {
        "type": "object",
        "properties": {
          "aspectRatio": {
            "type": "string",
            "description": "输出图片宽高比。",
            "enum": [
              "1:1",
              "3:2",
              "2:3",
              "3:4",
              "1:4",
              "4:1",
              "4:3",
              "4:5",
              "5:4",
              "1:8",
              "8:1",
              "9:16",
              "16:9",
              "21:9",
              "9:21"
            ]
          },
          "imageSize": {
            "type": "string",
            "description": "输出分辨率，使用大写 K；官方仅列出 1K、2K、4K。",
            "enum": [
              "1K",
              "2K",
              "4K"
            ]
          }
        }
      },
      "GenerateContentResponse": {
        "type": "object",
        "properties": {
          "candidates": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Candidate"
            }
          },
          "promptFeedback": {
            "type": "object",
            "description": "提示词反馈，例如请求被拦截的原因。"
          },
          "usageMetadata": {
            "$ref": "#/components/schemas/UsageMetadata"
          }
        }
      },
      "Candidate": {
        "type": "object",
        "properties": {
          "content": {
            "type": "object",
            "properties": {
              "role": {
                "type": "string",
                "examples": [
                  "model"
                ]
              },
              "parts": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ResponsePart"
                }
              }
            }
          },
          "finishReason": {
            "type": "string",
            "description": "生成结束原因，例如 STOP。",
            "examples": [
              "STOP"
            ]
          }
        }
      },
      "ResponsePart": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "description": "模型返回的文本。"
          },
          "inlineData": {
            "type": "object",
            "required": [
              "mimeType",
              "data"
            ],
            "properties": {
              "mimeType": {
                "type": "string",
                "examples": [
                  "image/png"
                ]
              },
              "data": {
                "type": "string",
                "description": "Base64 编码的输出图片。"
              }
            }
          },
          "thought": {
            "type": "boolean",
            "description": "是否为思考内容；保存最终图片时跳过值为 true 的部分。"
          },
          "thoughtSignature": {
            "type": "string",
            "description": "模型返回的思考签名；多轮对话时保留。"
          }
        }
      },
      "UsageMetadata": {
        "type": "object",
        "properties": {
          "promptTokenCount": {
            "type": "integer",
            "minimum": 0,
            "description": "输入 token 数。"
          },
          "candidatesTokenCount": {
            "type": "integer",
            "minimum": 0,
            "description": "候选内容 token 数。"
          },
          "totalTokenCount": {
            "type": "integer",
            "minimum": 0,
            "description": "总 token 数。"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "description": "错误信息对象，具体字段取决于错误来源。",
            "properties": {
              "message": {
                "type": "string",
                "description": "错误信息。"
              },
              "code": {
                "type": [
                  "string",
                  "integer"
                ],
                "description": "错误码。"
              },
              "status": {
                "type": "string",
                "description": "上游错误状态（如返回）。"
              },
              "type": {
                "type": "string",
                "description": "错误类型（如返回）。"
              },
              "param": {
                "type": "string",
                "description": "错误关联参数或请求标识（如返回）。"
              }
            }
          }
        }
      }
    }
  }
}
```
