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

# Nanobanana 图像生成

> - Nano Banana 2 (gemini-3.1-flash-image-preview) 模型支持文本转图片、图生图、图像编辑等多种生成模式
- 异步处理模式，使用返回的任务ID [进行查询](/pages/zh/api-manual/task-management/get-task-detail)
- 生成的图像链接，有效期为24小时，请尽快保存




## OpenAPI

````yaml openapi/zh/gemini-3.1-flash-image-preview.json POST /v1/images/generations
openapi: 3.1.0
info:
  title: Nano Banana 2
  version: '1.0'
servers:
  - url: https://api.aihubmax.com
security:
  - BearerAuth: []
paths:
  /v1/images/generations:
    post:
      tags:
        - Image > Nanobanana
      summary: Nano Banana 2
      description: >
        - Nano Banana 2 (gemini-3.1-flash-image-preview)
        模型支持文本转图片、图生图、图像编辑等多种生成模式

        - 异步处理模式，使用返回的任务ID
        [进行查询](/pages/zh/api-manual/task-management/get-task-detail)

        - 生成的图像链接，有效期为24小时，请尽快保存
      operationId: gemini-3.1-flash-image-preview
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GeminiImageGenRequest'
            examples:
              gemini_3_1_flash_text_to_image_1k:
                summary: Gemini 3.1 Flash — text-to-image (1K)
                value:
                  model: gemini-3.1-flash-image-preview
                  prompt: A futuristic city skyline at dusk, cyberpunk style
                  aspect_ratio: '16:9'
                  resolution: 1K
              gemini_3_1_flash_image_editing_with_image_search:
                summary: Gemini 3.1 Flash — image editing with image search
                value:
                  model: gemini-3.1-flash-image-preview
                  prompt: Replace the background with a tropical beach
                  image_urls:
                    - https://example.com/photo.jpg
                  aspect_ratio: match_input_image
                  resolution: 2K
                  image_search: true
      responses:
        '200':
          $ref: '#/components/responses/TaskCreated'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
components:
  schemas:
    GeminiImageGenRequest:
      type: object
      required:
        - model
        - prompt
      properties:
        model:
          description: '`gemini-3.1-flash-image-preview`：支持文生图、图生图、图像编辑'
          examples:
            - gemini-3.1-flash-image-preview
          type: string
          default: gemini-3.1-flash-image-preview
        prompt:
          description: |
            图像生成提示词

            **说明：**
            - 文生图模式：描述想要生成的图像内容
            - 图像编辑模式：描述对参考图的编辑指令
          type: string
          example: A futuristic city skyline at dusk, cyberpunk style
        aspect_ratio:
          default: '1:1'
          description: >
            输出图像宽高比


            **模型差异：**

            - `gemini-3.1-flash-image-preview`：可用范围覆盖
            `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`、`match_input_image`

            - `gemini-3-pro-image-preview`：可用范围覆盖
            `1:1`、`2:3`、`3:2`、`3:4`、`4:3`、`4:5`、`5:4`、`9:16`、`16:9`、`21:9`、`match_input_image`


            **说明：**

            - `match_input_image` 表示尽量沿用输入图像的宽高比
          type: string
          example: '1:1'
        resolution:
          default: 1K
          description: |
            输出图像分辨率

            **模型差异：**
            - `gemini-3.1-flash-image-preview`：支持 `512`、`0.5K`、`1K`、`2K`、`4K`
            - `gemini-3-pro-image-preview`：支持 `1K`、`2K`、`4K`

            **说明：**
            - `512` 与 `0.5K` 都表示 half-size 输出
            - `1K`：约 1MP
            - `2K`：约 4MP
            - `4K`：约 16MP
          type: string
          example: '512'
        image_urls:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          default: null
          description: |
            参考/编辑图片列表

            **模型差异：**
            - `gemini-3.1-flash-image-preview`：支持图生图和图像编辑
            - `gemini-3-pro-image-preview`：支持图像编辑

            **说明：**
            - 传入后自动切换到图像编辑模式
            - 推荐使用公开可访问的图片 URL
          example:
            - https://example.com/photo.jpg
        output_format:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: |-
            输出格式

            **说明：**
            - 两个模型都可以声明该字段
            - 常见值：`jpg`、`png`、`webp`


            > 非必须不要传这个参数。
          x-advanced: true
          example: png
        google_search:
          anyOf:
            - type: boolean
            - type: 'null'
          default: null
          description: >-
            启用搜索获取实时信息


            **说明：**

            - `gemini-3.1-flash-image-preview` 与 `gemini-3-pro-image-preview`
            都可以声明该字段



            > 非必须不要传这个参数。
          x-advanced: true
          example: true
        image_search:
          anyOf:
            - type: boolean
            - type: 'null'
          default: null
          description: |-
            启用图像搜索辅助生成

            **模型差异：**
            - `gemini-3.1-flash-image-preview`：支持
            - `gemini-3-pro-image-preview`：不支持


            > 非必须不要传这个参数。
          x-advanced: true
          example: true
    TaskResponse:
      type: object
      properties:
        created:
          type: integer
          description: 任务创建时间戳
          example: 1757165031
        id:
          type: string
          description: 任务ID
          example: task-unified-1757165031-uyujaw3d
        model:
          type: string
          description: 实际使用的模型名称
        object:
          type: string
          description: 任务的具体类型
          enum:
            - image.generation.task
        progress:
          type: integer
          description: 任务进度百分比 (0-100)
          minimum: 0
          maximum: 100
          example: 0
        status:
          type: string
          description: 任务状态
          enum:
            - pending
            - processing
            - completed
            - failed
          example: pending
        task_info:
          type: object
          description: 异步任务信息
          properties:
            can_cancel:
              type: boolean
              description: 任务是否可以取消
              example: true
            estimated_time:
              type: integer
              description: 预计完成时间（秒）
              example: 45
        type:
          type: string
          description: 任务的输出类型
          enum:
            - image
          example: image
    ErrorResponse400:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 请求格式错误
            type:
              type: string
              example: invalid_request_error
    ErrorResponse401:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: API密钥无效
            type:
              type: string
              example: authentication_error
    ErrorResponse402:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 账户余额不足
            type:
              type: string
              example: insufficient_quota
    ErrorResponse422:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 参数校验失败
            type:
              type: string
              example: validation_error
    ErrorResponse429:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 请求频率超限
            type:
              type: string
              example: rate_limit_error
    ErrorResponse500:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 服务器内部错误
            type:
              type: string
              example: server_error
    ErrorResponse503:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 服务暂不可用，请稍后重试
            type:
              type: string
              example: service_unavailable
  responses:
    TaskCreated:
      description: 任务创建成功
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/TaskResponse'
    BadRequest:
      description: 请求格式错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Unauthorized:
      description: 未授权
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse401'
    PaymentRequired:
      description: 余额不足
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse402'
    UnprocessableEntity:
      description: 参数校验失败
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse422'
    TooManyRequests:
      description: 请求频率超限
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse429'
    InternalServerError:
      description: 服务器内部错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse500'
    ServiceUnavailable:
      description: 服务暂不可用
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse503'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |
        ## 所有接口均需要使用Bearer Token进行认证 ##

        使用时在请求头中添加：

        `Authorization: Bearer YOUR_API_KEY`

````