> ## 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 image editing API

> Edit images with Nano Banana through BetterToken’s Gemini API. Send reference images and editing instructions, try requests online, and read the image response.

export const GeminiImageInput = ({labels}) => {
  const [images, setImages] = useState([]);
  const [busy, setBusy] = useState(false);
  const [feedback, setFeedback] = useState("");
  const selection = useRef(0);
  const inputId = useId();
  const readImages = async event => {
    const version = ++selection.current;
    const files = Array.from(event.target.files || []);
    setImages([]);
    setFeedback("");
    if (files.some(file => !["image/png", "image/jpeg"].includes(file.type))) {
      setFeedback(labels[4]);
      setBusy(false);
      return;
    }
    setBusy(true);
    try {
      const next = await Promise.all(files.map(file => new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.onload = () => resolve({
          name: file.name,
          type: file.type,
          data: String(reader.result).split(",")[1]
        });
        reader.onerror = reject;
        reader.onabort = reject;
        reader.readAsDataURL(file);
      })));
      if (version === selection.current) setImages(next);
    } catch {
      if (version === selection.current) setFeedback(labels[5]);
    } finally {
      if (version === selection.current) setBusy(false);
    }
  };
  const copy = async value => {
    try {
      await navigator.clipboard.writeText(value);
      setFeedback(labels[2]);
    } catch {
      setFeedback(labels[3]);
    }
  };
  return <section className="bt-gemini-input not-prose" aria-label={labels[0]}>
      <label htmlFor={inputId}>{labels[0]}</label>
      <input id={inputId} type="file" accept="image/png,image/jpeg" multiple onChange={readImages} />
      <p>{labels[7]}</p>
      <p role="status" aria-live="polite">{busy ? labels[6] : feedback}</p>
      {images.map((image, index) => <div key={index} className="bt-gemini-input-image">
          <div className="bt-gemini-input-header">
            <img src={"data:" + image.type + ";base64," + image.data} alt={image.name} />
            <span>{image.name}</span>
            <code>{image.type}</code>
            <button type="button" title={labels[1]} aria-label={labels[1] + " " + image.name} onClick={() => copy(image.data)}><Icon icon="copy" size={16} /></button>
          </div>
          <textarea aria-label={labels[1] + " " + image.name} rows={3} readOnly value={image.data} spellCheck={false} />
        </div>)}
    </section>;
};

Send a reference image and an editing instruction to 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.

## Reference images

Use a separate part for each text instruction and image. `inlineData.data` contains raw base64 without a Data URL prefix. Use PNG or JPEG reference images; this endpoint accepts JSON, not multipart uploads or image URLs.

Before sending, replace `REPLACE_WITH_IMAGE_BASE64` with your image’s base64 and set `inlineData.mimeType` to match the file. The sample instruction describes a mug; change it too if you use a different subject.

<GeminiImageInput labels={["Reference images","Copy base64","Copied","Select and copy the base64 below.","Select PNG or JPEG images.","Could not read the image. Please select it again.","Preparing images...","Images are converted locally. In the Playground, replace inlineData.data with the copied base64 and set inlineData.mimeType to the displayed MIME type. Keep each additional image in a separate part."]} />

## Try a request

Prepare your reference image first. Enter your BetterToken API Key in **x-goog-api-key** and select **model**. In **contents**, provide the editing instruction and image data. Check that `inlineData.data` has been replaced and `inlineData.mimeType` matches the file, 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>

Use non-streaming `generateContent`. Files / `fileData`, Batch, Interactions, and streaming are not supported by this integration.

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

* [Text-to-image](/en/api-reference/gemini-images-generations)
* [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-edits.en.json POST /v1beta/models/{model}:generateContent
openapi: 3.1.0
info:
  title: Gemini image editing API
  description: >-
    Edit images with Nano Banana through BetterToken’s Gemini API. Send
    reference images and editing instructions, try requests online, and read the
    image response.
  version: 1.0.0
servers:
  - url: https://bettertoken.ai
security:
  - geminiApiKey: []
paths:
  /v1beta/models/{model}:generateContent:
    post:
      summary: Gemini image editing API
      description: >-
        Send a reference image and an editing instruction to 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: editGeminiImage_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: >-
                                    Change the mug to red. Keep its shape, the
                                    background, and the lighting unchanged.
                              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 image bytes encoded as base64,
                                        without a Data URL prefix. Before
                                        sending, replace
                                        REPLACE_WITH_IMAGE_BASE64 with data from
                                        your own PNG or JPEG image.
                                      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: >-
                        Change the mug to red. Keep its shape, the background,
                        and the lighting unchanged.
                    - inlineData:
                        mimeType: image/png
                        data: REPLACE_WITH_IMAGE_BASE64
              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.