> ## 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 OpenAI 聊天格式

> 通过 OpenAI 聊天接口调用 NanoBanana，适合特价分组及 OpenAI SDK 用户

## 可使用的模型

| 模型 ID            | 说明                    |
| ---------------- | --------------------- |
| `nanobanana`     | 标准版                   |
| `nanobanana_pro` | 高质量版                  |
| `nanobanana_2`   | 第二代，**特价分组专用，仅支持此格式** |

## 图像配置

通过请求体的 `extra_body` 字段传入 Google 扩展参数：

```json
{
  "extra_body": {
    "google": {
      "image_config": {
        "aspect_ratio": "16:9",
        "image_size": "2K"
      }
    }
  }
}
```

## 响应格式

图像以 Markdown 内嵌于 `choices[0].message.content`：

```
![image](data:image/jpeg;base64,/9j/4AAQ...)
```

## 与聊天接口的关系

路径 `/v1/chat/completions` 被聊天补全接口共用；此处专门描述
`model` 为 NanoBanana ID 时的图像生成行为与特有的 `extra_body` 参数。


## OpenAPI

````yaml /openapi/images.zh.yaml post /v1/chat/completions
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:
  /v1/chat/completions:
    post:
      tags:
        - NanoBanana
      summary: NanoBanana OpenAI 聊天格式生成图像
      description: |
        通过 OpenAI Chat Completions 格式调用 NanoBanana 图像生成模型。
        适合已使用 OpenAI SDK 的场景，或需要使用特价分组的 `nanobanana_2` 模型时
        （该模型**仅支持此格式**，不支持 Gemini 原生格式）。

        图像以 Markdown 格式内嵌于响应消息的 `content` 字段中：
        `![image](data:image/jpeg;base64,<图片base64>)`。

        通过 `extra_body.google.image_config` 配置宽高比和分辨率。

        > **注意**：此接口路径 `/v1/chat/completions` 与聊天补全接口相同，
        > 但 `model` 字段传入 NanoBanana 模型 ID 时，InfinityBlue 会自动路由到图像生成后端。
        > 在 Mintlify 文档体系中，本页面作为独立的图像生成文档页呈现；
        > 如需对接文档构建工具，请确认路径复用不会导致 operationId 冲突。
      operationId: createNanoBananaImageViaChat
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NanoBananaChatRequest'
            examples:
              basic:
                summary: 基础文生图
                value:
                  model: nanobanana_pro
                  stream: false
                  messages:
                    - role: user
                      content: 画一只猫，坐在月光下的屋顶上
                  extra_body:
                    google:
                      image_config:
                        aspect_ratio: '16:9'
                        image_size: 2K
              nanobanana2_budget:
                summary: NanoBanana 2（特价分组）
                value:
                  model: nanobanana_2
                  stream: false
                  messages:
                    - role: user
                      content: 一只熊猫坐在竹林里吃竹子，水彩画风格
                  extra_body:
                    google:
                      image_config:
                        aspect_ratio: '1:1'
                        image_size: 1K
      responses:
        '200':
          description: 成功生成图像
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NanoBananaChatResponse'
        '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:
    NanoBananaChatRequest:
      type: object
      required:
        - model
        - messages
      description: NanoBanana OpenAI 聊天格式图像生成请求体。
      properties:
        model:
          type: string
          description: |
            NanoBanana 模型 ID。可选值：`nanobanana`、`nanobanana_pro`、`nanobanana_2`。
            特价分组的 `nanobanana_2` 仅支持此格式，不支持 Gemini 原生格式。
          examples:
            - nanobanana_pro
            - nanobanana_2
        stream:
          type: boolean
          default: false
          description: 是否流式返回。图像生成通常设为 `false`。
        messages:
          type: array
          description: 对话消息列表，包含用户的图像生成提示。
          items:
            type: object
            required:
              - role
              - content
            properties:
              role:
                type: string
                description: 消息角色。
                enum:
                  - user
                  - system
                  - assistant
              content:
                type: string
                description: 消息内容，对于图像生成即为文本提示词。
        extra_body:
          type: object
          description: |
            扩展参数，通过 `google.image_config` 传入图像配置（宽高比和分辨率）。
          properties:
            google:
              type: object
              description: Google 扩展参数。
              properties:
                image_config:
                  type: object
                  description: 图像生成配置。
                  required:
                    - aspect_ratio
                    - image_size
                  properties:
                    aspect_ratio:
                      type: string
                      description: |
                        输出图片宽高比。可选值：`1:1`、`3:4`、`4:3`、`9:16`、`16:9`。
                      examples:
                        - '16:9'
                    image_size:
                      type: string
                      description: |
                        输出图片分辨率等级。可选值：`1K`、`2K`、`4K`。
                      examples:
                        - 2K
    NanoBananaChatResponse:
      type: object
      description: NanoBanana OpenAI 聊天格式响应体。图像以 Markdown 内嵌于消息内容中。
      properties:
        id:
          type: string
          description: 本次请求的唯一标识。
          examples:
            - chatcmpl-20251211160744809365000fdOhL0KY
        model:
          type: string
          description: 实际处理请求的模型 ID。
          examples:
            - nanobanana_pro
        object:
          type: string
          description: 对象类型。
          examples:
            - chat.completion
        created:
          type: integer
          description: 创建时间的 Unix 时间戳（秒）。
          examples:
            - 1765440499
        choices:
          type: array
          description: 生成结果列表。
          items:
            type: object
            properties:
              index:
                type: integer
                description: 结果序号。
              message:
                type: object
                description: 生成的消息，`content` 字段包含 Markdown 格式的内嵌图像。
                properties:
                  role:
                    type: string
                    examples:
                      - assistant
                  content:
                    type: string
                    description: |
                      消息内容。图像以 Markdown 格式内嵌：
                      `![image](data:image/jpeg;base64,<base64数据>)`。
                    examples:
                      - '![image](data:image/jpeg;base64,/9j/4AAQ...)'
              finish_reason:
                type: string
                description: 生成结束原因。
                examples:
                  - stop
        usage:
          type: object
          description: Token 用量统计。
          properties:
            prompt_tokens:
              type: integer
              description: 提示词消耗的 token 数。
            completion_tokens:
              type: integer
              description: 补全消耗的 token 数（含图像生成 token）。
            total_tokens:
              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
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: |
        使用 Bearer Token 认证，格式：`Authorization: Bearer sk-xxxxxx`。
        在 [控制台](https://api.getinfinityblue.com/console) 获取 API Key。

````