Skip to main content

model guide

Nano Banana 2

gemini-3.1-flash-image

Balanced

A balanced image route for everyday generation and image editing, with multiple output sizes and aspect ratios exposed by the current Studio configuration.

0.5K to 4KImage editing
Model details
Model ID
gemini-3.1-flash-image
Reference price
$0.055/ call
Output sizes
512 / 1K / 2K / 4K
API format
Gemini native

Prompt presets

These are the settings currently available in YingTu.

Product photo

A clean product photo of a matte ceramic coffee mug on a light stone table, soft window light, natural shadows, minimal styling.

Editorial landscape

An editorial travel photograph of a mountain lake at sunrise, layered atmospheric depth, natural color, fine detail.

Reference edit

Preserve the main subject and composition. Replace the background with a quiet modern studio using soft directional daylight.

Available settings

These are the settings currently available in the Image Studio.

Best for

  • Everyday image generation
  • Reference-guided edits
  • Testing several output sizes

Check before use

  • The listed speed is an estimate, not a delivery guarantee.
  • Editing quality depends on the reference image and instruction.
  • Check text, logos, hands, and small details before use.
Image editing: Supported

API quickstart

This example uses the same request format as the Image Studio.

View API page
gemini-3.1-flash-image
import base64
import mimetypes
import os
import sys

import requests

API_KEY = os.environ.get("LAOZHANG_API_KEY")
if not API_KEY:
    raise RuntimeError("Set the LAOZHANG_API_KEY environment variable before running this example.")

API_URL = "https://api2.laozhang.ai/v1beta/models/gemini-3.1-flash-image:generateContent"
REQUEST_TIMEOUT_SECONDS = 500

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
}

payload = {
    "contents": [{
        "parts": [
            {"text": "A clean product photo of a matte ceramic coffee mug on a light stone table, soft window light, natural shadows, minimal styling."}
        ]
    }],
    "generationConfig": {
        "responseModalities": ["IMAGE"],
        "imageConfig": {
            "imageSize": "2K"
        }
    }
}

try:
    response = requests.post(
        API_URL,
        headers=headers,
        json=payload,
        timeout=REQUEST_TIMEOUT_SECONDS,
    )
except requests.Timeout as error:
    print(
        "Request timed out after 500 seconds. The result status may be unknown; "
        "check call and billing logs before retrying.",
        file=sys.stderr,
    )
    raise SystemExit(1) from error

if response.status_code != 200:
    print(f"API error {response.status_code}: {response.text}", file=sys.stderr)
    raise SystemExit(1)

try:
    result = response.json()
except ValueError as error:
    print("API returned a non-JSON response.", file=sys.stderr)
    raise SystemExit(1) from error

if not isinstance(result, dict):
    print("API returned an unexpected JSON shape.", file=sys.stderr)
    raise SystemExit(1)

image_part = None
for candidate in result.get("candidates", []):
    for part in candidate.get("content", {}).get("parts", []):
        inline_data = part.get("inlineData") or part.get("inline_data")
        if inline_data and inline_data.get("data"):
            image_part = inline_data
            break
    if image_part:
        break

if not image_part:
    response_id = result.get("responseId", "not provided")
    print(f"No image data in response. responseId={response_id}", file=sys.stderr)
    raise SystemExit(1)

mime_type = image_part.get("mimeType") or image_part.get("mime_type") or "image/png"
encoded_image = image_part["data"]
if encoded_image.startswith("data:"):
    header, encoded_image = encoded_image.split(",", 1)
    mime_type = header[5:].split(";", 1)[0] or mime_type

extension_by_mime = {
    "image/jpeg": "jpg",
    "image/png": "png",
    "image/webp": "webp",
    "image/gif": "gif",
}
extension = extension_by_mime.get(mime_type, "bin")
output_path = f"output.{extension}"

with open(output_path, "wb") as output_file:
    output_file.write(base64.b64decode(encoded_image, validate=True))

print(f"Image saved: {output_path} ({mime_type})")

Studio examples

These gallery images do not include the model or prompt used to create them. They are visual examples, not test results for this model.

Studio example
Studio example
Studio example

Test record

YingTu test results

This section shows only YingTu test results that are ready for public review. When no result is available, we say so instead of showing draft data.

No published result

Product appearance consistency

Whether the product’s shape, proportions, colors, logo, and packaging text remain consistent.

No published result

Background replacement

Whether the subject and its edges remain intact while only the requested background changes.