> ## 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 AI 模型提交 Nanobanana 图像生成或编辑任务。

### 使用模式

1. **文本到图像生成**
   * 提供 `prompt` 并将 `type` 设置为 "TEXTTOIAMGE"
   * 模型将根据文本描述生成新图像

2. **图像到图像编辑**
   * 提供 `prompt`、`imageUrls` 并将 `type` 设置为 "IMAGETOIAMGE"
   * 模型将根据提示编辑输入图像

### 重要说明

* 使用 `numImages` 参数每次请求可以生成 1-4 张图像
* 使用 `image_size` 参数指定图像的宽高比
* 回调地址 (`callBackUrl`) 是必填的，用于接收任务完成通知
* 任务完成后将通过 POST 请求发送结果到您的回调地址
* 如需轮询任务状态，可使用获取任务详情接口
* 根据您的需求选择合适的生成类型：
  * TEXTTOIAMGE：文本到图像生成
  * IMAGETOIAMGE：使用输入图像进行图像编辑


## OpenAPI

````yaml cn/nanobanana-api/nanobanana-api-cn.json post /api/v1/nanobanana/generate
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:
    post:
      summary: 生成或编辑图像
      description: |-
        提交 Nanobanana 图像生成或编辑任务。

        ### 使用模式
        1. **文本到图像生成** (TEXTTOIAMGE)
           - 提供 `prompt` 并将 `type` 设置为 "TEXTTOIAMGE"
           - 模型将根据文本描述生成新图像

        2. **图像到图像编辑** (IMAGETOIAMGE)
           - 提供 `prompt`、`imageUrls` 并将 `type` 设置为 "IMAGETOIAMGE"
           - 模型将根据提示编辑输入图像

        ### 重要说明
        - 每次请求可以生成 1-4 张图像
        - 任务完成通知需要回调 URL
      operationId: generate-or-edit-image
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                prompt:
                  type: string
                  description: 生成内容的提示词
                  example: 夕阳下宁静的山景，湖面倒映着橙色的天空
                numImages:
                  type: integer
                  minimum: 1
                  maximum: 4
                  description: 生成图片数量，最小值为 1，最大值为 4
                  default: 1
                  example: 1
                imageUrls:
                  type: array
                  items:
                    type: string
                    format: uri
                  description: 用于图像编辑模式的输入图像 URL 数组
                  example:
                    - https://example.com/input-image.jpg
                type:
                  type: string
                  enum:
                    - IMAGETOIAMGE
                    - TEXTTOIAMGE
                  description: |-
                    生成类型：
                    - TEXTTOIAMGE: 文本到图像
                    - IMAGETOIAMGE: 图像编辑
                  example: TEXTTOIAMGE
                watermark:
                  type: string
                  description: 添加到生成图像上的水印文字
                  example: NanoBanana
                image_size:
                  type: string
                  enum:
                    - '1:1'
                    - '9:16'
                    - '16:9'
                    - '3:4'
                    - '4:3'
                    - '3:2'
                    - '2:3'
                    - '5:4'
                    - '4:5'
                    - '21:9'
                  description: |-
                    图像宽高比。支持的比例：
                    - 1:1: 正方形
                    - 9:16: 竖屏（手机）
                    - 16:9: 横屏（宽屏）
                    - 3:4: 竖屏
                    - 4:3: 横屏（传统）
                    - 3:2: 横屏（照片）
                    - 2:3: 竖屏（照片）
                    - 5:4: 竖屏（接近正方形）
                    - 4:5: 竖屏（接近正方形）
                    - 21:9: 超宽横屏
                  example: '1:1'
                callBackUrl:
                  type: string
                  format: uri
                  description: 回调地址，用于接收任务完成通知（必填）
                  example: https://your-callback-url.com/callback
              required:
                - prompt
                - type
                - callBackUrl
              example:
                prompt: 夕阳下宁静的山景，湖面倒映着橙色的天空
                numImages: 1
                type: TEXTTOIAMGE
                image_size: '16:9'
                callBackUrl: https://your-callback-url.com/callback
      responses:
        '200':
          description: 请求成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                    enum:
                      - 200
                      - 400
                      - 401
                      - 500
                    description: |-
                      响应状态码

                      - **200**: 成功
                      - **400**: 参数错误
                      - **401**: 未授权
                      - **500**: 服务器内部错误
                  msg:
                    type: string
                    description: 响应消息
                    example: success
                  data:
                    type: object
                    properties:
                      taskId:
                        type: string
                        description: 用于跟踪生成进度的任务 ID
                        example: task12345
              example:
                code: 200
                msg: success
                data:
                  taskId: task12345
        '400':
          description: 参数错误
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                    example: 400
                  msg:
                    type: string
                    example: 参数错误
        '401':
          description: 未授权
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                    example: 401
                  msg:
                    type: string
                    example: 未授权
        '500':
          description: 服务器内部错误
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                    example: 500
                  msg:
                    type: string
                    example: 服务器内部错误
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 已泄露，请立即在管理页面重置

````