Skip to content

Gemini 3.1 Flash Image(Nano Banana 2)

POST/v1beta/models/gemini-3.1-flash-image:generateContent

Generate or edit images with Nano Banana 2 through the native Google Gemini protocol. SandBase preserves the provider request and response payload instead of converting it to Chat Completions.

Request body

Send a native Gemini GenerateContent body. Provider-defined fields are passed through for this model.

arraycontentsrequired

Gemini Content objects containing the prompt and optional input images.

array<string>generationConfig.responseModalitiesrequired

Requested output modalities. Include IMAGE; include TEXT when you also want a text part.

Optional<object>generationConfig.imageConfig

Image options such as aspectRatio, when supported by the provider.

Edit an image ​

Add the source image as an inlineData part next to the text instruction. Use the MIME type of the bytes you send:

json
{
  "contents": [{
    "role": "user",
    "parts": [
      {"text": "Keep the subject unchanged and turn the background into a paper-cut landscape."},
      {"inlineData": {"mimeType": "image/png", "data": "<base64-input-image>"}}
    ]
  }],
  "generationConfig": {"responseModalities": ["IMAGE"]}
}

Response handling ​

Read generated media from the returned candidate parts. Because this model uses native passthrough, provider-defined field casing and MIME metadata are returned as received. Decode the base64 payload and verify the actual media bytes before choosing a file extension.

Official Google resources ​