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

# 生成图像 (Nanobanana 2)

> 使用 /api/v1/nanobanana/generate-2 提交 NanoBanana 新版图像生成任务。

### 重要说明

* 响应中返回的任务 ID 用于通过获取任务详情接口查询任务状态
* 如果提供了 `callBackUrl`，任务完成后会向该地址发送回调通知
* 文本提示词 `prompt` 最长支持 20000 字符，建议描述清晰、具体
* `imageUrls` 为空数组时为纯文本生图，填写 URL 时为图生图/参考图模式
* 可通过 `aspectRatio`、`resolution`、`outputFormat` 控制生成图像的比例、清晰度和格式

### 参数概览

* **prompt**：文本提示词，必填，最长 20000 字符
* **imageUrls**：参考图 URL 数组，文生图时传空数组，最多 14 张
* **aspectRatio**：生成图像宽高比，支持 1:1、1:4、1:8、2:3、3:2、3:4、4:1、4:3、4:5、5:4、8:1、9:16、16:9、21:9、auto
* **resolution**：分辨率质量，可选 1K / 2K / 4K
* **googleSearch**：是否启用 Google Web Search 增强，默认 false
* **outputFormat**：输出格式，支持 png / jpg，默认 jpg
* **callBackUrl**：可选回调 URL，用于接收任务完成通知


## OpenAPI

````yaml cn/nanobanana-api/nanobanana-api-cn.json post /api/v1/nanobanana/generate-2
openapi: 3.0.0
info:
  title: NanoBanana API
  description: NanoBanana API 文档 - 图像生成和编辑 API
  version: 1.0.0
  contact:
    name: 技术支持
    email: support@nanobananaapi.ai
servers:
  - url: https://api.nanobananaapi.ai
    description: API 服务器
security:
  - BearerAuth: []
paths:
  /api/v1/nanobanana/generate-2:
    post:
      summary: 生成图像 (Nanobanana 2)
      operationId: generate-image-2
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - prompt
              properties:
                prompt:
                  type: string
                  description: 文本提示词（必填），用于控制生成图像的内容，最长 20000 字符
                  maxLength: 20000
                  example:
                    - a happy dog running in the park
                imageUrls:
                  type: array
                  description: 图像到图像模式下使用的参考图 URL。文本到图像模式下该字段为空数组。
                  items:
                    type: string
                    format: uri
                  default: []
                  maxItems: 14
                aspectRatio:
                  type: string
                  description: 生成图像的宽高比
                  enum:
                    - '1:1'
                    - '1:4'
                    - '1:8'
                    - '2:3'
                    - '3:2'
                    - '3:4'
                    - '4:1'
                    - '4:3'
                    - '4:5'
                    - '5:4'
                    - '8:1'
                    - '9:16'
                    - '16:9'
                    - '21:9'
                    - auto
                  default: auto
                resolution:
                  type: string
                  description: 输出分辨率质量，可选：1K、2K、4K
                  enum:
                    - 1K
                    - 2K
                    - 4K
                  default: 1K
                googleSearch:
                  type: boolean
                  description: 是否启用 Google Web Search 增强，根据实时信息生成图像
                  default: false
                outputFormat:
                  type: string
                  description: 输出图像格式
                  enum:
                    - png
                    - jpg
                  default: jpg
                callBackUrl:
                  type: string
                  format: uri
                  description: 可选回调 URL，用于在任务完成时接收异步通知
              example:
                prompt: a happy dog running in the park
                imageUrls: []
                aspectRatio: auto
                resolution: 1K
                googleSearch: false
                outputFormat: jpg
                callBackUrl: https://example-callback.com
      responses:
        '200':
          description: 请求成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                    description: 响应状态码
                    example: 200
                  message:
                    type: string
                    description: 响应消息
                    example: success
                  data:
                    type: object
                    properties:
                      taskId:
                        type: string
                        description: 用于查询任务状态的任务 ID
                        example: task_12345678
              example:
                code: 200
                message: success
                data:
                  taskId: task_12345678
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: |-
        所有 API 都需要通过 Bearer Token 进行身份验证。

        获取 API Key：
        1. 访问 [API Key 管理页面](https://nanobananaapi.ai/api-key) 获取您的 API Key

        使用方法：
        在请求头中添加：
        Authorization: Bearer YOUR_API_KEY

        注意：
        - 请保护您的 API Key 安全，不要与他人分享
        - 如果您怀疑 API Key 已泄露，请立即在管理页面重置

````