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

# NanoBanana 原生格式

> 使用 Gemini 原生协议调用 NanoBanana，支持多图参考与高清输出

## 可使用的模型

| 模型 ID            | 说明                                 |
| ---------------- | ---------------------------------- |
| `nanobanana`     | 标准版，均衡速度与质量                        |
| `nanobanana_pro` | 高质量版，适合产品图、精细风格统一                  |
| `nanobanana_2`   | 第二代，特价分组**仅支持 OpenAI 聊天格式**（见独立接口） |

## 多图参考

在 `contents[].parts` 中连续追加多个 `inline_data` 对象，
每个对象对应一张参考图的 Base64 数据，即可实现多图参考输入。

## 分辨率配置

`generationConfig.imageConfig` 中：

* `aspectRatio`：`1:1`、`3:4`、`4:3`、`9:16`、`16:9`
* `imageSize`：`1K`、`2K`、`4K`

## 思考内容

设置 `generationConfig.thinkingConfig.includeThoughts: true`
可在响应中返回模型的推理过程。


## OpenAPI

````yaml /openapi/images.zh.yaml post /v1beta/models/{model}:generateContent
openapi: 3.1.0
info:
  title: InfinityBlue API — 图像（Images）
  version: 1.0.0
  summary: 图像生成与编辑接口
  description: >
    InfinityBlue 图像接口支持 OpenAI 原生格式与 NanoBanana（Gemini 原生）格式，

    涵盖文生图、图像编辑以及多参考图融合生成等场景。


    ## 认证


    所有请求都需要在请求头中携带 API Key：


    ```

    Authorization: Bearer YOUR_API_KEY

    ```


    在 [控制台](https://api.getinfinityblue.com/console) 创建和管理你的 API Key。


    ## 接口格式约定


    | 路径前缀 | 兼容格式 |

    | --- | --- |

    | `/v1/images/*` | OpenAI Images API |

    | `/v1/chat/completions` | OpenAI Chat Completions（NanoBanana OpenAI 格式） |

    | `/v1beta/models/{model}:generateContent` | Google Gemini 原生（NanoBanana
    原生格式） |
  contact:
    name: InfinityBlue
    url: https://getinfinityblue.com
servers:
  - url: https://api.getinfinityblue.com
    description: 生产环境
security:
  - bearerAuth: []
tags:
  - name: 图像（Images）
    description: |
      OpenAI 兼容的图像生成与编辑接口，支持 `gpt-image-2` 等模型。
  - name: NanoBanana
    description: |
      NanoBanana 图像生成接口，支持原生 Gemini 格式与 OpenAI 聊天格式，
      可用于文生图、多参考图融合及风格统一等场景。
paths:
  /v1beta/models/{model}:generateContent:
    post:
      tags:
        - NanoBanana
      summary: NanoBanana 原生格式生成图像
      description: |
        通过 Gemini 原生格式调用 NanoBanana 图像生成模型。
        支持文生图、单图参考编辑及多图参考融合生成，
        可指定宽高比（`aspectRatio`）和分辨率等级（`imageSize`）。

        路径参数 `model` 传入 NanoBanana 模型 ID，例如 `nanobanana_pro`。
      operationId: createNanoBananaImageNative
      parameters:
        - name: model
          in: path
          required: true
          description: |
            NanoBanana 模型 ID，例如 `nanobanana_pro`。
            可选值：`nanobanana`、`nanobanana_pro`。
          schema:
            type: string
          example: nanobanana_pro
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NanoBananaRequest'
            examples:
              text_to_image:
                summary: 文生图（基础）
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 画一只猫，坐在月光下的屋顶上
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '16:9'
                      imageSize: 4K
              with_thinking:
                summary: 返回思考内容
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 画一只猫，坐在月光下的屋顶上
                  generationConfig:
                    thinkingConfig:
                      includeThoughts: true
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '16:9'
                      imageSize: 4K
              multi_reference:
                summary: 多图参考融合
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 结合这两张参考图，生成一张统一风格的产品宣传图，保留主体轮廓，整体更高级、简洁、明亮
                        - inline_data:
                            mimeType: image/jpeg
                            data: <base64_image_1>
                        - inline_data:
                            mimeType: image/jpeg
                            data: <base64_image_2>
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '1:1'
                      imageSize: 2K
      responses:
        '200':
          description: 成功生成图像
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NanoBananaResponse'
        '400':
          description: 请求参数错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: API Key 无效或缺失
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: 请求频率超限
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: 服务器内部错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    NanoBananaRequest:
      type: object
      required:
        - contents
        - generationConfig
      description: NanoBanana 原生格式图像生成/编辑请求体。
      properties:
        contents:
          type: array
          description: |
            对话内容列表。通常传入一条 `user` 消息；
            在该消息的 `parts` 中可同时放入文本提示和多张参考图片。
          items:
            $ref: '#/components/schemas/NanoBananaContent'
        generationConfig:
          $ref: '#/components/schemas/NanoBananaGenerationConfig'
    NanoBananaResponse:
      type: object
      description: NanoBanana 原生格式响应体。
      properties:
        candidates:
          type: array
          description: 模型生成的候选结果列表。
          items:
            type: object
            properties:
              content:
                type: object
                description: 候选结果的内容。
                properties:
                  role:
                    type: string
                    description: 消息角色（通常为 `model`）。
                  parts:
                    type: array
                    description: 内容片段列表，包含文本和/或图像数据。
                    items:
                      type: object
                      description: 单个内容片段，包含文本或图像 inline_data。
              finishReason:
                type: string
                description: 生成结束原因。
              safetyRatings:
                type: array
                description: 安全评级列表。
                items:
                  type: object
        usageMetadata:
          type: object
          description: Token 用量统计。
          properties:
            promptTokenCount:
              type: integer
              description: 提示词消耗的 token 数。
            candidatesTokenCount:
              type: integer
              description: 候选结果消耗的 token 数。
            totalTokenCount:
              type: integer
              description: 总消耗 token 数。
    ErrorResponse:
      type: object
      description: 标准错误响应。
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: 错误信息。
              examples:
                - 无效的尺寸。支持的尺寸为 1024x1024、1536x1024、1024x1536。
            type:
              type: string
              description: 错误类型。
              examples:
                - invalid_request_error
            param:
              type:
                - string
                - 'null'
              description: 相关参数。
              examples:
                - size
            code:
              type:
                - string
                - 'null'
              description: 错误代码。
              examples:
                - invalid_size
    NanoBananaContent:
      type: object
      required:
        - role
        - parts
      description: 单条消息对象。
      properties:
        role:
          type: string
          description: 消息角色，通常固定为 `user`，表示用户输入的图像生成或编辑请求。
          examples:
            - user
        parts:
          type: array
          description: |
            消息内容片段列表，支持混合传入文本与图片。
            一般第一个 part 为文本提示（`text`），
            后续可追加一个或多个 `inline_data` 作为参考图，实现多图参考输入。
          items:
            $ref: '#/components/schemas/NanoBananaPart'
    NanoBananaGenerationConfig:
      type: object
      required:
        - responseModalities
        - imageConfig
      description: 生成参数配置，用于控制返回模态、图片规格等。
      properties:
        thinkingConfig:
          type: object
          description: 思考过程返回配置，图像生成场景通常可选。
          properties:
            includeThoughts:
              type: boolean
              description: 是否返回模型思考内容。`true` 表示返回；图像生成通常传 `false` 或不传。
              examples:
                - false
        responseModalities:
          type: array
          description: |
            响应模态列表，指定接口返回的数据类型。
            图像生成常用值：`TEXT`（文字说明）和 `IMAGE`（生成图片）。
          items:
            type: string
            enum:
              - TEXT
              - IMAGE
          examples:
            - - TEXT
              - IMAGE
        imageConfig:
          $ref: '#/components/schemas/NanoBananaImageConfig'
    NanoBananaPart:
      type: object
      description: |
        消息片段对象。每个片段二选一：
        传 `text` 表示文本提示，传 `inline_data` 表示图片内容。
        若需多图参考，可在 `parts` 中连续传入多个 `inline_data` 对象。
      properties:
        text:
          type: string
          description: |
            文本提示词，用于描述生成目标、风格、构图、主体保留要求等。
          examples:
            - 结合这两张参考图，生成一张统一风格的产品宣传图，保留主体轮廓，整体更高级、简洁、明亮
        inline_data:
          $ref: '#/components/schemas/NanoBananaInlineData'
    NanoBananaImageConfig:
      type: object
      required:
        - aspectRatio
        - imageSize
      description: 图片输出配置，用于设置生成图片的宽高比和分辨率等级。
      properties:
        aspectRatio:
          type: string
          description: |
            输出图片宽高比。应根据投放场景选择合适比例。
            可选值：`1:1`、`3:4`、`4:3`、`9:16`、`16:9`。
          examples:
            - '1:1'
            - '16:9'
        imageSize:
          type: string
          description: |
            输出图片分辨率等级。数值越高清晰度越高，生成耗时也可能增加。
            可选值：`1K`、`2K`、`4K`。
          examples:
            - 2K
            - 4K
    NanoBananaInlineData:
      type: object
      required:
        - mimeType
        - data
      description: |
        内联图片数据，用于传入参考图或输入图像。
        支持在 `parts` 中提供多张图片（多图参考输入）；
        模型会结合所有图片与文本提示进行综合生成。
      properties:
        mimeType:
          type: string
          description: 图片 MIME 类型，如 `image/jpeg`、`image/png`、`image/webp`，需与实际格式一致。
          examples:
            - image/jpeg
        data:
          type: string
          description: |
            图片的 Base64 编码数据，不包含 `data:image/...;base64,` 前缀。
            可传入一张或多张图片；多图场景下，每张图对应一个独立的 `inline_data.data`。
          examples:
            - <base64_encoded_image_data>
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: |
        使用 Bearer Token 认证，格式：`Authorization: Bearer sk-xxxxxx`。
        在 [控制台](https://api.getinfinityblue.com/console) 获取 API Key。

````