> ## 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.

# 生成图像

> 根据文本提示生成图像，支持多种尺寸、质量和输出格式

## 可使用的模型

| 模型 ID         | 说明                        |
| ------------- | ------------------------- |
| `gpt-image-2` | GPT Image 2，支持灵活尺寸与多种输出格式 |

> 快照版本（如 `gpt-image-2-2026-04-21`）暂不可用，请使用 `gpt-image-2`。

## 尺寸说明（`gpt-image-2`）

`size` 参数默认为 `auto`，支持灵活尺寸：

* 边长不超过 `3840px`
* 宽高均为 `16` 的倍数
* 长边与短边比例不超过 `3:1`
* 总像素介于 `655,360` 到 `8,294,400` 之间

常用预设：`1024x1024`、`1536x1024`（横向）、`1024x1536`（纵向）、
`2048x2048`、`2048x1152`、`3840x2160`、`2160x3840`。

也支持自定义尺寸（如 `1024x768`），只要宽高均为 16 的倍数且符合上述约束即可。

## 流式输出

本站暂不支持流式输出。`stream` 和 `partial_images` 参数会被接受但不生效，
响应始终以完整 JSON 一次性返回。

## 质量与格式

* `quality`：本站暂不支持 `quality` 分档，统一使用 `auto` 级别输出。
  参数会被接受但各级别间无实际差异。
* `output_format`：`png`（默认）/ `jpeg` / `webp`
* `output_compression`：仅对 `jpeg` / `webp` 生效，取值 `0`–`100`


## OpenAPI

````yaml /openapi/images.zh.yaml post /v1/images/generations
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/images/generations:
    post:
      tags:
        - 图像（Images）
      summary: 生成图像
      description: |
        根据文本提示词生成图像。支持 `gpt-image-2` 模型，
        提供灵活的尺寸配置与多种输出格式。

        完全兼容 OpenAI Images API——把官方 SDK 的 base URL 指向 InfinityBlue 即可直接使用。
      operationId: createImageGeneration
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageGenerationRequest'
            examples:
              basic:
                summary: 基础方图
                value:
                  model: gpt-image-2
                  prompt: 一只可爱的海獭宝宝漂浮在蓝色海面上
                  size: 1024x1024
              landscape:
                summary: 横向宽屏图
                value:
                  model: gpt-image-2
                  prompt: 未来都市夜景，霓虹灯倒映在雨后的街道上，赛博朋克风格
                  size: 1536x1024
                  output_format: png
              jpeg_compressed:
                summary: JPEG 压缩输出
                value:
                  model: gpt-image-2
                  prompt: 宁静的日式庭院，樱花飘落，阳光透过树叶洒下
                  output_format: jpeg
                  output_compression: 80
                  size: 1024x1024
              portrait:
                summary: 纵向竖图
                value:
                  model: gpt-image-2
                  prompt: 一座古老的灯塔矗立在悬崖边，海浪拍打着礁石，日落余晖
                  size: 1024x1536
                  output_format: png
              webp_output:
                summary: WebP 格式输出
                value:
                  model: gpt-image-2
                  prompt: 一碗热气腾腾的日式拉面，俯视角度，美食摄影风格
                  size: 1024x1024
                  output_format: webp
                  output_compression: 90
              url_response:
                summary: 返回图片 URL
                value:
                  model: gpt-image-2
                  prompt: 简约风格的红苹果图标，扁平设计，白色背景
                  size: 1024x1024
                  response_format: url
      responses:
        '200':
          description: 成功生成图像
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageGenerationResponse'
        '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:
    ImageGenerationRequest:
      type: object
      required:
        - model
        - prompt
      description: 图像生成请求体。
      properties:
        model:
          type: string
          description: |
            用于图像生成的模型 ID，传入 `gpt-image-2`。
            快照版本（如 `gpt-image-2-2026-04-21`）暂不可用。
          examples:
            - gpt-image-2
        prompt:
          type: string
          description: |
            所需图像的文本描述。对于 `gpt-image-2`，最长支持 32,000 个字符。
          examples:
            - 一只可爱的海獭宝宝漂浮在蓝色海面上
        'n':
          type: integer
          minimum: 1
          maximum: 1
          default: 1
          description: |
            本站暂不支持 `n` 参数，默认 `n=1`，每次请求输出 1 张图片。
            如需多张图片，请循环调用接口。
        size:
          type: string
          default: auto
          description: |
            生成图像的尺寸。对于 `gpt-image-2`，默认为 `auto`，支持灵活尺寸（边长不超过
            3840px、宽高均为 16 的倍数、长宽比不超过 3:1、总像素在 655,360–8,294,400 之间）；
            常用预设包括 `1024x1024`、`1536x1024`、`1024x1536`、`2048x2048`、
            `2048x1152`、`3840x2160`、`2160x3840`。
          examples:
            - 1024x1024
            - 1536x1024
            - auto
        background:
          type: string
          description: |
            生成图像的背景设置。对于 `gpt-image-2`，默认为 `auto`，
            可选 `opaque`（不透明）或 `auto`。
            `gpt-image-2` 不支持 `transparent`（透明背景），传入该值会返回 400 错误。
          enum:
            - opaque
            - transparent
            - auto
        moderation:
          type: string
          description: |
            内容审核级别。对于 `gpt-image-2`，默认为 `auto`（标准），
            可选 `low`（宽松）。
          enum:
            - auto
            - low
        quality:
          type: string
          description: |
            本站暂不支持 `quality` 分档，统一使用 `auto` 级别输出。
            参数会被接受但各级别间无实际差异。
          enum:
            - low
            - medium
            - high
            - auto
        stream:
          type: boolean
          default: false
          description: |
            本站暂不支持流式输出。参数会被接受但不生效，
            响应始终以完整 JSON 一次性返回。
        style:
          type: string
          description: |
            图像风格参数，仅 DALL·E 3 支持。
            `gpt-image-2` 下参数会被接受但无实际效果。
        output_format:
          type: string
          description: |
            生成图像的输出格式。对于 `gpt-image-2`，默认为 `png`，
            可选 `png`、`jpeg`、`webp`。仅 GPT Image 系列支持此参数。
          enum:
            - png
            - jpeg
            - webp
        output_compression:
          type: integer
          minimum: 0
          maximum: 100
          description: |
            输出图像的压缩质量（0–100）。对于 `gpt-image-2`，
            仅在 `output_format` 为 `jpeg` 或 `webp` 时生效。
        partial_images:
          type: integer
          minimum: 0
          maximum: 3
          default: 0
          description: |
            流式返回时的中间帧数量（0–3）。依赖流式输出功能，
            由于本站暂不支持流式输出，此参数当前不可用。
        response_format:
          type: string
          default: b64_json
          description: |
            返回图像的格式。默认为 `b64_json`，返回 Base64 编码的图像数据；
            设为 `url` 时返回图像的临时访问 URL（建议尽快下载或转存）。
          enum:
            - b64_json
            - url
        user:
          type: string
          description: |
            代表终端用户的唯一标识符，可用于监控和滥用检测。
    ImageGenerationResponse:
      type: object
      description: 图像生成响应体。
      properties:
        created:
          type: integer
          description: 创建时间的 Unix 时间戳（秒）。
          examples:
            - 1713833628
        data:
          type: array
          description: 生成的图像列表。
          items:
            type: object
            properties:
              b64_json:
                type: string
                description: Base64 编码的图像数据（当 `response_format=b64_json` 时返回）。
              url:
                type: string
                description: 图像的临时访问 URL（当 `response_format=url` 时返回）。
        usage:
          $ref: '#/components/schemas/ImageUsage'
    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
    ImageUsage:
      type: object
      description: 本次请求的 token 用量统计。
      properties:
        total_tokens:
          type: integer
          description: 总消耗 token 数。
        input_tokens:
          type: integer
          description: 输入消耗的 token 数。
        output_tokens:
          type: integer
          description: 输出消耗的 token 数（含图像生成 token）。
        input_tokens_details:
          type: object
          description: 输入 token 明细。
          properties:
            text_tokens:
              type: integer
              description: 文本 token 数。
            image_tokens:
              type: integer
              description: 图像 token 数。
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: |
        使用 Bearer Token 认证，格式：`Authorization: Bearer sk-xxxxxx`。
        在 [控制台](https://api.getinfinityblue.com/console) 获取 API Key。

````