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

# Gemini text-to-image API

> Generate images with Nano Banana through BetterToken’s Gemini API. Try model selection, prompts, resolutions and aspect ratios in the interactive API playground.

Generate an image from a text description with Nano Banana Pro, 2, or 2.1.

`POST /v1beta/models/{model}:generateContent`

Text-to-image and image editing use the same endpoint. Image editing adds a reference image to the request.

## Try a request

Enter your BetterToken API Key in **x-goog-api-key**, select **model**, and edit the text in **contents**. Start with `1K` and `1:1`, then click **Send**.

<Note>
  Clicking **Send** makes a real generation request and may incur charges. Wait for the synchronous response. After a timeout or disconnection, check usage records and the request result before sending it again.
</Note>

All three offer `1K`, `2K`, and `4K`. Nano Banana 2 and 2.1 support 14 aspect ratios; Pro supports 10. `X-BetterToken-Max-Images` is a delivery and billing cap, not a guaranteed image count. [Aspect ratios](/en/api-reference/nano-banana#aspect-ratios)

<Warning>
  BetterToken API does not support search-assisted image generation, including Google Web Search and Image Search grounding. Do not add search tools.
</Warning>

Text-to-image requires only a text description; no reference image is needed. Use non-streaming `generateContent`. Files, Batch, Interactions, and streaming are not supported.

## Read the response

Images are returned in `candidates[].content.parts[].inlineData`. Iterate over the parts, skip `thought: true`, decode `data`, and choose the file extension from `mimeType`. Do not assume the image is always the first part or always PNG.

## Related guides

* [Image editing](/en/api-reference/gemini-images-edits)
* [SDK, image saving, and multi-turn editing](/en/api-reference/nano-banana)
* [Model introduction](/en/model-updates/nano-banana)
* <a href={"https://bettertoken.ai/pricing"}>Model plaza</a>


## OpenAPI

````yaml api-reference/gemini-images-generations.en.json POST /v1beta/models/{model}:generateContent
openapi: 3.1.0
info:
  title: Gemini text-to-image API
  description: >-
    Generate images with Nano Banana through BetterToken’s Gemini API. Try model
    selection, prompts, resolutions and aspect ratios in the interactive API
    playground.
  version: 1.0.0
servers:
  - url: https://bettertoken.ai
security:
  - geminiApiKey: []
paths:
  /v1beta/models/{model}:generateContent:
    post:
      summary: Gemini text-to-image API
      description: >-
        Generate an image from a text description with Nano Banana Pro, 2, or
        2.1. BetterToken API does not support search-assisted image generation,
        including Google Web Search and Image Search grounding. Do not add
        search tools.
      operationId: generateGeminiImage_en
      parameters:
        - name: model
          in: path
          required: true
          description: BetterToken Model ID. Choose one of the three Nano Banana models.
          schema:
            type: string
            enum:
              - nano-banana-pro
              - nano-banana-2
              - nano-banana-2.1
            default: nano-banana-2.1
        - name: X-BetterToken-Max-Images
          in: header
          description: >-
            Maximum number of returned and billable images, not a guaranteed
            count. Defaults to 1.
          schema:
            type: integer
            minimum: 1
            maximum: 4
            default: 1
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - contents
              properties:
                contents:
                  type: array
                  description: >-
                    Conversation contents. Keep the complete model content and
                    thoughtSignature for follow-up edits.
                  minItems: 1
                  items:
                    type: object
                    required:
                      - parts
                    properties:
                      role:
                        type: string
                        description: >-
                          Use user for a new request; use model for previous
                          model responses in editing history.
                        enum:
                          - user
                          - model
                        default: user
                      parts:
                        type: array
                        description: >-
                          Text and image parts. Put text and inlineData in
                          separate parts.
                        minItems: 1
                        items:
                          anyOf:
                            - type: object
                              required:
                                - text
                              properties:
                                text:
                                  type: string
                                  description: Image description or editing instruction.
                                  example: >-
                                    A studio product photograph of a blue
                                    ceramic mug on a white table.
                              additionalProperties: true
                            - type: object
                              required:
                                - inlineData
                              properties:
                                inlineData:
                                  type: object
                                  description: Reference image embedded as base64.
                                  required:
                                    - mimeType
                                    - data
                                  properties:
                                    mimeType:
                                      type: string
                                      description: The reference image MIME type.
                                      enum:
                                        - image/png
                                        - image/jpeg
                                      example: image/png
                                    data:
                                      type: string
                                      description: >-
                                        Raw base64 image bytes, without a Data
                                        URL prefix.
                                      contentEncoding: base64
                                      example: REPLACE_WITH_IMAGE_BASE64
                                  additionalProperties: false
                              additionalProperties: true
                    additionalProperties: false
                generationConfig:
                  type: object
                  description: Image generation settings.
                  properties:
                    responseModalities:
                      type: array
                      description: Explicitly request image output.
                      items:
                        type: string
                        enum:
                          - IMAGE
                      default:
                        - IMAGE
                    candidateCount:
                      type: integer
                      enum:
                        - 1
                      default: 1
                      description: Omit or use the integer 1. Do not send root-level n.
                    imageConfig:
                      type: object
                      description: Output image settings.
                      properties:
                        imageSize:
                          type: string
                          description: Output resolution. Use uppercase K.
                          enum:
                            - 1K
                            - 2K
                            - 4K
                          default: 1K
                        aspectRatio:
                          type: string
                          description: >-
                            Aspect ratio. Pro supports 10 ratios; 2 and 2.1 also
                            support 1:4, 4:1, 1:8, and 8:1.
                          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'
                          default: '1:1'
                      additionalProperties: false
                  additionalProperties: false
              additionalProperties: false
            example:
              contents:
                - role: user
                  parts:
                    - text: >-
                        A studio product photograph of a blue ceramic mug on a
                        white table.
              generationConfig:
                responseModalities:
                  - IMAGE
                candidateCount: 1
                imageConfig:
                  imageSize: 1K
                  aspectRatio: '1:1'
      responses:
        '200':
          description: Generation response. Inspect final image parts and finishReason.
          content:
            application/json:
              schema:
                type: object
                properties:
                  candidates:
                    type: array
                    items:
                      type: object
                      properties:
                        content:
                          type: object
                          properties:
                            role:
                              type: string
                            parts:
                              type: array
                              items:
                                type: object
                                properties:
                                  text:
                                    type: string
                                  thought:
                                    type: boolean
                                  thoughtSignature:
                                    type: string
                                  inlineData:
                                    type: object
                                    properties:
                                      mimeType:
                                        type: string
                                      data:
                                        type: string
                                        contentEncoding: base64
                        finishReason:
                          type: string
                  promptFeedback:
                    type: object
                    additionalProperties: true
                  usageMetadata:
                    type: object
                    additionalProperties: true
              example:
                candidates:
                  - content:
                      role: model
                      parts:
                        - inlineData:
                            mimeType: image/png
                            data: BASE64_IMAGE_DATA
                    finishReason: STOP
        '400':
          description: Invalid parameters or unsupported capability.
        '401':
          description: Missing or invalid API Key.
        '402':
          description: Insufficient balance.
        '429':
          description: Rate limit or upstream busy.
        '500':
          description: Generation service error. Check the request result before retrying.
components:
  securitySchemes:
    geminiApiKey:
      type: apiKey
      in: header
      name: x-goog-api-key
      description: BetterToken API Key.

````

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