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

# Nano Banana 2 API

> 支持 0.5K / 1K / 2K / 4K 文生图和参考图编辑。

## 参数与输入模式

`model` 和 `input` 始终必填。通过 URL 传参考图时，请使用公网图片直链，并确保任务结束前始终可访问。

| 请求场景 | input 必填字段 |
| - | - |
| 文生图 | `prompt` |
| 参考图编辑 | `prompt` 和非空的 `image_urls` 数组。 |

## 使用场景

```json 文生图 theme={null}
{
  "model": "nano-banana-2",
  "input": {
    "prompt": "Product photograph of a cobalt blue teapot on a wooden table, lit by a window.",
    "aspect_ratio": "16:9"
  }
}
```

```json 图片编辑 theme={null}
{
  "model": "nano-banana-2",
  "input": {
    "prompt": "Replace the background with a plain ivory studio backdrop.",
    "image_urls": [
      "https://cdn.example.com/reference.png"
    ],
    "aspect_ratio": "auto"
  }
}
```

```json 用 Google 搜索制作花卉图解 theme={null}
{
  "model": "nano-banana-2",
  "input": {
    "prompt": "Create an illustrated guide to seasonal flowers in Kyoto.",
    "google_search": true,
    "google_image_search": true
  }
}
```

## 试用与价格

参考图已包含在价格内。每张成功图片按实际生成渠道收费，失败图片不扣积分。

> [card] [在线试用](https://apistable.ai/zh/models/nano-banana-2#try)
>
> 设置参数并在线生成图片。

> [card] [查看价格](https://apistable.ai/zh/models/nano-banana-2#pricing)
>
> 按分辨率查看标准价和回退价。


## OpenAPI

````yaml openapi-nano-banana-2-zh.json POST /api/v1/tasks/create_task
openapi: 3.1.0
info:
  title: APIstable API
  version: 1.0.0-preview
  description: >-
    Public /api/v1 protocol. Valid API keys have the same account-scoped access.
    Read the selected model documentation for its ID, supported inputs, result
    format and availability before submitting. No client submission idempotency
    or max_credits. Availability, pricing, file retention and callback formats
    follow the selected model contract. Unconfigured operations return 503.
servers:
  - url: https://apistable.ai
    description: API Stable API
security: []
paths:
  /api/v1/tasks/create_task:
    post:
      summary: Nano Banana 2 API
      description: 支持 0.5K / 1K / 2K / 4K 文生图和参考图编辑。
      operationId: nano-banana-2
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - input
              additionalProperties: false
              properties:
                model:
                  type: string
                  enum:
                    - nano-banana-2
                  example: nano-banana-2
                  description: 本页对应的 APIstable 模型 ID。
                input:
                  $schema: https://json-schema.org/draft/2020-12/schema
                  type: object
                  properties:
                    prompt:
                      type: string
                      minLength: 1
                      description: 生成或编辑图片的文字描述。
                    resolution:
                      default: 1K
                      type: string
                      enum:
                        - 0.5K
                        - 1K
                        - 2K
                        - 4K
                    aspect_ratio:
                      default: '1:1'
                      type: string
                      enum:
                        - '1:1'
                        - '4:3'
                        - '3:4'
                        - '16:9'
                        - '9:16'
                        - '3:2'
                        - '2:3'
                        - '21:9'
                        - '4:5'
                        - '5:4'
                        - auto
                        - '1:4'
                        - '4:1'
                        - '1:8'
                        - '8:1'
                      description: 传 `auto` 由模型决定比例。
                    image_urls:
                      default: []
                      description: >-
                        最多 14 张公网 HTTP(S) 图片或 PNG、JPEG、WebP 的 Base64 Data
                        URL。单张最多 10 MB。JSON 请求体上限为 64,000 字节，大图请传 URL。
                      maxItems: 14
                      type: array
                      items:
                        anyOf:
                          - type: string
                            format: uri
                          - type: string
                            format: uri
                    google_search:
                      type: boolean
                      description: 启用 Google 文本搜索。
                    google_image_search:
                      type: boolean
                      description: '启用时必须同时传入 `google_search: true`。'
                    output_count:
                      default: 1
                      description: 独立生成 1–4 张图片。
                      type: integer
                      minimum: 1
                      maximum: 4
                    official_fallback:
                      default: false
                      description: 标准渠道明确失败后，允许尝试兼容的回退渠道。回退要求提示词为 3–50,000 字符。
                      type: boolean
                    nsfw_check:
                      default: false
                      type: boolean
                      description: 审核提示词和参考图。
                  required:
                    - prompt
                  additionalProperties: false
                  allOf:
                    - if:
                        properties:
                          google_image_search:
                            const: true
                        required:
                          - google_image_search
                      then:
                        properties:
                          google_search:
                            const: true
                        required:
                          - google_search
                callback_url:
                  type: string
                  format: uri
                  description: 任务完成时接收签名回调的公网 HTTPS 地址。须为可直接访问的地址，不能跳转到其他地址。省略时可轮询查询任务接口。
            example:
              model: nano-banana-2
              input:
                prompt: >-
                  Product photograph of a cobalt blue teapot on a wooden table,
                  lit by a window.
                aspect_ratio: '16:9'
      responses:
        '200':
          description: 已受理。使用 `task_id` [查询任务](/zh/query-task)，或通过 `callback_url` 接收结果。
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - msg
                  - data
                additionalProperties: false
                properties:
                  code:
                    const: 200
                    type: integer
                  msg:
                    const: success
                    type: string
                  data:
                    type: object
                    required:
                      - task_id
                    additionalProperties: false
                    properties:
                      task_id:
                        type: string
              example:
                code: 200
                msg: success
                data:
                  task_id: 00000000-0000-4000-8000-000000000001
        '400':
          description: >-
            40001 invalid JSON, 40002 invalid input/callback or input rejected
            by screening, 40003 unsupported parameter.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Invalid or revoked API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '402':
          description: '40201: Insufficient credits (live acceptance).'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: '40301: Website session requests require the APIstable site origin.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: '40401: Unknown model or resource not found in this account.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: '40901: Resource incompatible with this operation.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '410':
          description: '41001: Source audio or temporary resource has expired.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '413':
          description: '41301: Request too large.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: '42201: Requested capability combination is not enabled.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: '42901: Rate/concurrency limit (live acceptance).'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: '50301: Service unavailable. No live submission or charge.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      callbacks:
        Webhook:
          '{$request.body#/callback_url}':
            post:
              requestBody:
                required: true
                description: >-
                  任务成功或失败后，APIstable 向创建任务时传入的 `callback_url` 发送 JSON POST。验签后返回
                  HTTP 2xx 确认接收。


                  用 `data.status` 判断生成结果。部分成功也返回 `succeeded`。`data.result.urls`
                  列出成功图片，图片保留 14 天。全部失败时为 `failed`，`data.result` 为
                  `null`，`data.message` 提供失败原因。


                  签名和去重使用 `X-APIstable-Signature`、`X-APIstable-Timestamp` 和
                  `X-APIstable-Event-Id`。详见 [Webhook 安全与验签](/zh/webhook-secret)。


                  **Webhook 请求体示例**


                  ```json

                  {
                    "code": 200,
                    "msg": "success",
                    "data": {
                      "task_id": "00000000-0000-4000-8000-000000000001",
                      "model": "nano-banana-2",
                      "status": "succeeded",
                      "created_at": "2026-11-13T08:30:00.000Z",
                      "completed_at": "2026-11-13T08:30:08.000Z",
                      "duration": 8000,
                      "charged_credits": 3,
                      "message": "",
                      "input": "{\"prompt\":\"Studio photograph of a cobalt blue teapot.\",\"resolution\":\"1K\"}",
                      "result": {
                        "urls": [
                          "https://cdn.example.com/generated/image.png"
                        ],
                        "items": [
                          {
                            "id": "00000000-0000-4000-8000-000000000002",
                            "status": "succeeded",
                            "charged_credits": 3,
                            "urls": [
                              "https://cdn.example.com/generated/image.png"
                            ]
                          }
                        ]
                      }
                    }
                  }

                  ```
                content:
                  application/json:
                    schema:
                      type: object
                      required:
                        - code
                        - msg
                        - data
                      properties:
                        code:
                          const: 200
                          type: integer
                        msg:
                          const: success
                          type: string
                        data:
                          type: object
                          additionalProperties: false
                          required:
                            - task_id
                            - model
                            - status
                            - created_at
                            - completed_at
                            - duration
                            - charged_credits
                            - message
                            - input
                            - result
                          properties:
                            task_id:
                              type: string
                            model:
                              type: string
                              const: nano-banana-2
                            status:
                              type: string
                              enum:
                                - succeeded
                                - failed
                            created_at:
                              type: string
                              format: date-time
                            completed_at:
                              type:
                                - string
                                - 'null'
                              format: date-time
                            duration:
                              type:
                                - integer
                                - 'null'
                              minimum: 0
                              description: >-
                                Total elapsed milliseconds; null while
                                processing.
                            charged_credits:
                              type:
                                - number
                                - 'null'
                              minimum: 0
                              description: Final charged Credits; null until completion.
                            message:
                              type: string
                              description: >-
                                Failure reason for failed tasks, or an
                                actionable pending-settlement message while
                                processing; empty on success.
                            input:
                              type: string
                              contentMediaType: application/json
                              description: JSON-serialized accepted model input.
                            result:
                              type:
                                - object
                                - 'null'
                              required:
                                - urls
                                - items
                              properties:
                                urls:
                                  type: array
                                  maxItems: 100
                                  items:
                                    type: string
                                    format: uri
                                items:
                                  type: array
                                  maxItems: 4
                                  items:
                                    type: object
                                    required:
                                      - id
                                      - status
                                      - charged_credits
                                      - urls
                                    properties:
                                      id:
                                        type: string
                                        format: uuid
                                      status:
                                        type: string
                                      charged_credits:
                                        type: number
                                        minimum: 0
                                      urls:
                                        type: array
                                        items:
                                          type: string
                                          format: uri
                    example:
                      code: 200
                      msg: success
                      data:
                        task_id: 00000000-0000-4000-8000-000000000001
                        model: nano-banana-2
                        status: succeeded
                        created_at: '2026-11-13T08:30:00.000Z'
                        completed_at: '2026-11-13T08:30:08.000Z'
                        duration: 8000
                        charged_credits: 3
                        message: ''
                        input: >-
                          {"prompt":"Studio photograph of a cobalt blue
                          teapot.","resolution":"1K"}
                        result:
                          urls:
                            - https://cdn.example.com/generated/image.png
                          items:
                            - id: 00000000-0000-4000-8000-000000000002
                              status: succeeded
                              charged_credits: 3
                              urls:
                                - https://cdn.example.com/generated/image.png
              responses:
                2XX:
                  description: 已接收 Webhook。
              method: post
              type: path
            path: '{$request.body#/callback_url}'
      security:
        - bearerAuth: []
components:
  schemas:
    Error:
      type: object
      required:
        - code
        - msg
        - data
      properties:
        code:
          type: integer
        msg:
          type: string
        data:
          type: 'null'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        登录 APIstable 后，在 [API Key 管理](https://apistable.ai/zh/console/keys)
        创建并复制密钥。


        每次调用都要在 HTTP 请求头传入：


        ```http

        Authorization: Bearer YOUR_API_KEY

        ```


        将 YOUR_API_KEY 替换为你创建的 API Key。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.