> ## 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 3.1 Flash Lite Image

> Google's Gemini 3.1 Flash Lite Image for AI image generation and editing via Gemini API.

Gemini 3.1 Flash Lite Image is Google's low-latency, cost-effective image generation and editing model, available through Anyfast via the native Gemini API. It is also known as Nano Banana Lite and is designed for high-volume interactive image use cases.

<Info>
  Google lists `gemini-3.1-flash-lite-image` as the stable model ID for Nano Banana Lite. The official model page shows a June 2026 latest update and describes the model as optimized for sub-2 second latency, lower TPU compute cost, and high-volume image generation and editing.
</Info>

## Key capabilities

* **Text-to-image** — Generate images from text descriptions
* **Image editing** — Pass a reference image in `inline_data` alongside your text instruction
* **Low latency** — Targeted for sub-2 second end-to-end latency
* **Aspect ratio control** — `1:1`, `3:2`, `2:3`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9`
* **Resolution control** — Supports `1K` (1024px). 2K and 4K are not supported.
* **Thinking control** — Supports `minimal` and `high` thinking levels
* **Multi-modal output** — Return both the image and a text caption with `responseModalities: ["TEXT", "IMAGE"]`
* **Watermarking** — SynthID is always on, with C2PA watermarking

> **Note:** If you need the generated image returned as a URL, select the **Aggregate-NanoUrl** group when creating your API token.

## Text-to-image example

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://www.anyfast.ai/v1beta/models/gemini-3.1-flash-lite-image:generateContent?key=YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "contents": [
        {
          "role": "user",
          "parts": [
            { "text": "Generate an image of a sunset over mountains" }
          ]
        }
      ],
      "generationConfig": {
        "responseModalities": ["TEXT", "IMAGE"],
        "imageConfig": {
          "aspectRatio": "16:9",
          "imageSize": "1K"
        }
      }
    }'
  ```

  ```python Python theme={null}
  import requests, base64

  url = "https://www.anyfast.ai/v1beta/models/gemini-3.1-flash-lite-image:generateContent"
  response = requests.post(url, params={"key": "YOUR_API_KEY"}, json={
      "contents": [
          {
              "role": "user",
              "parts": [{"text": "Generate an image of a sunset over mountains"}]
          }
      ],
      "generationConfig": {
          "responseModalities": ["TEXT", "IMAGE"],
          "imageConfig": {"aspectRatio": "16:9", "imageSize": "1K"}
      }
  })

  for part in response.json()["candidates"][0]["content"]["parts"]:
      image_part = part.get("inlineData") or part.get("inline_data")
      if image_part:
          with open("output.jpg", "wb") as f:
              f.write(base64.b64decode(image_part["data"]))
          print("Image saved to output.jpg")
      elif "text" in part:
          print("Caption:", part["text"])
  ```

  ```python GenAI SDK theme={null}
  import google.genai as genai

  client = genai.Client(api_key="YOUR_API_KEY")

  response = client.models.generate_content(
      model="gemini-3.1-flash-lite-image",
      contents="Generate an image of a sunset over mountains",
      config={
          "responseModalities": ["TEXT", "IMAGE"],
          "imageConfig": {
              "aspectRatio": "16:9",
              "imageSize": "1K"
          }
      }
  )

  for candidate in response.candidates:
      for part in candidate.content.parts:
          if part.inline_data:
              with open("output.jpg", "wb") as f:
                  f.write(part.inline_data.data)
              print("Image saved to output.jpg")
          elif part.text:
              print("Caption:", part.text)
  ```
</CodeGroup>

## Image editing example (with reference image)

Include both a `text` instruction and an `inline_data` reference image in the same `parts` array.

<CodeGroup>
  ```bash cURL theme={null}
  # First encode your image to base64:
  # BASE64=$(base64 -i your_photo.jpg)
  #
  # Then send the request:
  curl "https://www.anyfast.ai/v1beta/models/gemini-3.1-flash-lite-image:generateContent?key=YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "contents": [
        {
          "role": "user",
          "parts": [
            {
              "text": "Hi, this is a picture of me. Can you add a llama next to me?"
            },
            {
              "inline_data": {
                "mime_type": "image/jpeg",
                "data": "<YOUR_BASE64_ENCODED_IMAGE>"
              }
            }
          ]
        }
      ],
      "generationConfig": {
        "responseModalities": ["TEXT", "IMAGE"],
        "imageConfig": {
          "aspectRatio": "1:1",
          "imageSize": "1K"
        }
      }
    }'
  ```

  ```python Python theme={null}
  import requests, base64

  # Read and encode your reference image
  with open("your_photo.jpg", "rb") as f:
      image_b64 = base64.b64encode(f.read()).decode("utf-8")

  url = "https://www.anyfast.ai/v1beta/models/gemini-3.1-flash-lite-image:generateContent"
  response = requests.post(url, params={"key": "YOUR_API_KEY"}, json={
      "contents": [
          {
              "role": "user",
              "parts": [
                  {
                      "text": "Hi, this is a picture of me. Can you add a llama next to me?"
                  },
                  {
                      "inline_data": {
                          "mime_type": "image/jpeg",
                          "data": image_b64          # ← paste your base64 string here
                      }
                  }
              ]
          }
      ],
      "generationConfig": {
          "responseModalities": ["TEXT", "IMAGE"],
          "imageConfig": {"aspectRatio": "1:1", "imageSize": "1K"}
      }
  })

  for part in response.json()["candidates"][0]["content"]["parts"]:
      image_part = part.get("inlineData") or part.get("inline_data")
      if image_part:
          with open("output.jpg", "wb") as f:
              f.write(base64.b64decode(image_part["data"]))
          print("Image saved to output.jpg")
      elif "text" in part:
          print("Caption:", part["text"])
  ```

  ```python GenAI SDK theme={null}
  import google.genai as genai

  client = genai.Client(api_key="YOUR_API_KEY")

  # Read and encode your reference image
  with open("your_photo.jpg", "rb") as f:
      image_bytes = f.read()

  response = client.models.generate_content(
      model="gemini-3.1-flash-lite-image",
      contents=[
          "Hi, this is a picture of me. Can you add a llama next to me?",
          genai.types.Part.from_bytes(data=image_bytes, mime_type="image/jpeg")
      ],
      config={
          "responseModalities": ["TEXT", "IMAGE"],
          "imageConfig": {
              "aspectRatio": "1:1",
              "imageSize": "1K"
          }
      }
  )

  for candidate in response.candidates:
      for part in candidate.content.parts:
          if part.inline_data:
              with open("output.jpg", "wb") as f:
                  f.write(part.inline_data.data)
              print("Image saved to output.jpg")
          elif part.text:
              print("Caption:", part.text)
  ```
</CodeGroup>

## Parameters

| Parameter                                  | Type   | Required | Description                                                                      |
| ------------------------------------------ | ------ | -------- | -------------------------------------------------------------------------------- |
| `key`                                      | string | Yes      | API key (query parameter)                                                        |
| `contents[].parts[].text`                  | string | Yes      | Text prompt or instruction                                                       |
| `contents[].parts[].inline_data.mime_type` | string | No       | Reference image type: `image/jpeg`, `image/png`, `image/webp`                    |
| `contents[].parts[].inline_data.data`      | string | No       | Base64-encoded reference image                                                   |
| `generationConfig.responseModalities`      | array  | Yes      | `["IMAGE"]` or `["TEXT", "IMAGE"]`                                               |
| `generationConfig.imageConfig.aspectRatio` | string | No       | `1:1` / `3:2` / `2:3` / `3:4` / `4:3` / `4:5` / `5:4` / `9:16` / `16:9` / `21:9` |
| `generationConfig.imageConfig.imageSize`   | string | No       | `1K` only. 2K and 4K are not supported.                                          |

<Card title="API Reference" icon="code" href="/api-reference/model-api/google/gemini-3.1-flash-lite-image">
  View the interactive API playground for Gemini 3.1 Flash Lite Image.
</Card>

<script src="/feedback.js" />
