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

# gemini-nano-banana-2.1

> 根据文本、图片、视频或 PDF 输入生成图片和可选文本。



## OpenAPI

````yaml zh/api-reference/model-api/google/openapi/gemini-nano-banana-2-1/openapi.yaml POST /v1beta/models/gemini-nano-banana-2.1:generateContent
openapi: 3.1.0
info:
  title: Gemini Nano Banana 2.1
  description: 通过 AnyFast 原生 Gemini API 使用 Gemini Nano Banana 2.1 生成和编辑图片。
  version: 1.0.0
servers:
  - url: https://www.anyfast.ai
security: []
paths:
  /v1beta/models/gemini-nano-banana-2.1:generateContent:
    post:
      summary: 生成或编辑图片
      description: 根据文本、图片、视频或 PDF 输入生成图片和可选文本。
      operationId: GeminiNanoBanana21GenerateContent
      parameters:
        - name: key
          in: query
          required: true
          description: AnyFast API Key。
          schema:
            type: string
          example: YOUR_API_KEY
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateContentRequest'
            examples:
              textToImage:
                summary: 文生图
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 为一把半透明蓝色机械键盘设计简洁的 16:9 产品海报。
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    responseFormat:
                      image:
                        aspectRatio: '16:9'
                        imageSize: 2K
              imageEditing:
                summary: 图片编辑
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 保持产品不变，将背景替换为温暖的木质桌面。
                        - inline_data:
                            mime_type: image/png
                            data: YOUR_BASE64_IMAGE_DATA
                  generationConfig:
                    responseModalities:
                      - IMAGE
                    responseFormat:
                      image:
                        aspectRatio: '4:3'
                        imageSize: 2K
      responses:
        '200':
          description: 内容生成成功。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateContentResponse'
              example:
                candidates:
                  - content:
                      role: model
                      parts:
                        - text: 已生成产品海报。
                        - inlineData:
                            mimeType: image/png
                            data: iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ
                    finishReason: STOP
                usageMetadata:
                  promptTokenCount: 24
                  candidatesTokenCount: 1680
                  totalTokenCount: 1704
                modelVersion: gemini-nano-banana-2.1
                responseId: response_example
        '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'
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >
            curl
            "https://www.anyfast.ai/v1beta/models/gemini-nano-banana-2.1:generateContent?key=YOUR_API_KEY"
            \
              -H "Content-Type: application/json" \
              -d '{
                "contents": [{
                  "role": "user",
                  "parts": [{
                    "text": "为一把半透明蓝色机械键盘设计简洁的 16:9 产品海报。"
                  }]
                }],
                "generationConfig": {
                  "responseModalities": ["TEXT", "IMAGE"],
                  "thinkingConfig": {"thinkingLevel": "medium"},
                  "responseFormat": {
                    "image": {"aspectRatio": "16:9", "imageSize": "2K"}
                  }
                }
              }'
components:
  schemas:
    GenerateContentRequest:
      type: object
      required:
        - contents
      properties:
        contents:
          type: array
          minItems: 1
          description: 包含提示词和参考素材的对话内容。
          items:
            $ref: '#/components/schemas/Content'
        generationConfig:
          $ref: '#/components/schemas/GenerationConfig'
    GenerateContentResponse:
      type: object
      properties:
        candidates:
          type: array
          items:
            $ref: '#/components/schemas/Candidate'
        promptFeedback:
          type: object
          additionalProperties: true
        usageMetadata:
          $ref: '#/components/schemas/UsageMetadata'
        modelVersion:
          type: string
          example: gemini-nano-banana-2.1
        responseId:
          type: string
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: integer
            message:
              type: string
            status:
              type: string
    Content:
      type: object
      required:
        - parts
      properties:
        role:
          type: string
          enum:
            - user
            - model
          default: user
        parts:
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/Part'
    GenerationConfig:
      type: object
      properties:
        responseModalities:
          type: array
          description: 仅返回图片，或同时返回文本和图片。默认同时返回文本和图片。
          minItems: 1
          uniqueItems: true
          items:
            type: string
            enum:
              - TEXT
              - IMAGE
          example:
            - TEXT
            - IMAGE
        responseFormat:
          type: object
          properties:
            image:
              $ref: '#/components/schemas/ImageResponseFormat'
        thinkingConfig:
          $ref: '#/components/schemas/ThinkingConfig'
    Candidate:
      type: object
      properties:
        content:
          type: object
          properties:
            role:
              type: string
              example: model
            parts:
              type: array
              items:
                $ref: '#/components/schemas/ResponsePart'
        finishReason:
          type: string
          enum:
            - STOP
            - MAX_TOKENS
            - SAFETY
            - RECITATION
            - OTHER
        index:
          type: integer
        safetyRatings:
          type: array
          items:
            type: object
            additionalProperties: true
    UsageMetadata:
      type: object
      properties:
        promptTokenCount:
          type: integer
        candidatesTokenCount:
          type: integer
        totalTokenCount:
          type: integer
        thoughtsTokenCount:
          type: integer
    Part:
      type: object
      description: 文本或媒体内容块。根据内容类型填写对应字段。
      properties:
        text:
          type: string
          description: 文本提示词或编辑指令。
        inline_data:
          $ref: '#/components/schemas/InlineDataInput'
        file_data:
          $ref: '#/components/schemas/FileDataInput'
        video_metadata:
          $ref: '#/components/schemas/VideoMetadata'
    ImageResponseFormat:
      type: object
      properties:
        aspectRatio:
          type: string
          description: 输出图片宽高比。
          enum:
            - '1:1'
            - '1:4'
            - '1:8'
            - '2:3'
            - '3:2'
            - '3:4'
            - '4:1'
            - '4:3'
            - '4:5'
            - '5:4'
            - '8:1'
            - '9:16'
            - '16:9'
            - '21:9'
          example: '16:9'
        imageSize:
          type: string
          description: 输出分辨率，默认 1K。
          enum:
            - 1K
            - 2K
            - 4K
          default: 1K
    ThinkingConfig:
      type: object
      properties:
        thinkingLevel:
          type: string
          description: 思考强度，默认 medium。
          enum:
            - minimal
            - medium
            - high
          default: medium
        includeThoughts:
          type: boolean
          default: false
          description: 是否允许在响应中返回思考内容块。
    ResponsePart:
      type: object
      properties:
        text:
          type: string
        inlineData:
          type: object
          required:
            - mimeType
            - data
          properties:
            mimeType:
              type: string
              example: image/png
            data:
              type: string
              format: byte
              description: Base64 编码的生成图片。
        thought:
          type: boolean
          description: 为 true 时，该内容块属于模型思考过程而不是最终结果。
        thoughtSignature:
          type: string
          description: 继续多轮对话时需要保留的不透明签名。
    InlineDataInput:
      type: object
      required:
        - mime_type
        - data
      description: Base64 编码的内联图片、视频或 PDF 数据。
      properties:
        mime_type:
          type: string
          description: 编码内容的 MIME 类型。
          example: image/png
        data:
          type: string
          format: byte
          description: 不包含 data URL 前缀的 Base64 数据。
    FileDataInput:
      type: object
      required:
        - mime_type
        - file_uri
      description: 通过 Gemini Files API 上传的文件。
      properties:
        mime_type:
          type: string
          example: application/pdf
        file_uri:
          type: string
          description: 文件上传接口返回的 URI，或支持的公开视频 URI。
    VideoMetadata:
      type: object
      description: 视频输入采样配置。
      properties:
        fps:
          type: number
          exclusiveMinimum: 0
          example: 0.5

````

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