> ## AI Agent Context > Get the complete documentation index at: https://aistudio.google.com/docs/llms.txt > Use this file to discover all available pages. > For the full documentation in a single file, fetch: https://aistudio.google.com/docs/llms-full.txt # Nano Banana image generation {% id="nano-banana-image-generation" %} {% button href="https://aistudio.google.com" variant="ais" %}Try in Google AI Studio{% /button %} **Nano Banana** is the name for Gemini's native image generation capabilities. Gemini can generate and process images conversationally with text, images, video, or a combination. This lets you create, edit, and iterate on visuals with unprecedented control. ## Model selection {% id="model-selection" %} Nano Banana refers to the following models available in the Gemini API: * **Nano Banana 2.1**: The [Gemini Nano Banana 2.1](/docs/models/gemini-nano-banana-2.1) model (`gemini-nano-banana-2.1`). An update to Nano Banana 2, serving as the primary high-efficiency workhorse model for image generation and conversational editing. It maintains Flash-level speed and cost efficiency while delivering improved visual quality, text rendering, multi-turn consistency, and Google Search grounding across 1K, 2K, and 4K resolutions. * **Nano Banana 2 Lite**: The [Gemini 3.1 Flash Lite Image](/docs/models/gemini-3.1-flash-lite-image) model (`gemini-3.1-flash-lite-image`). The fastest and cheapest Gemini image model, engineered for velocity and scale where speed and cost are primary constraints. Not optimized for multiple reference inputs or multi-turn sequential editing. * **Nano Banana 2**: The [Gemini 3.1 Flash Image](/docs/models/gemini-3.1-flash-image) model (`gemini-3.1-flash-image`). The previous-generation high-efficiency workhorse model, optimized for speed, 4K generation, and multiple reference image consistency. Recommended for all new projects to use Nano Banana 2.1. * **Nano Banana Pro**: The [Gemini 3 Pro Image](/docs/models/gemini-3-pro-image) model (`gemini-3-pro-image`). The premium choice for complex visual tasks, utilizing advanced reasoning ("Thinking") to follow complex instructions, maintain brand consistency, and render high-fidelity text. * **Nano Banana**: The [Gemini 2.5 Flash Image](/docs/models/gemini-2.5-flash-image) model (`gemini-2.5-flash-image`). The legacy model of the Nano Banana series. Recommended migration path is Nano Banana 2 Lite for higher quality, faster speeds, and lower pricing. All generated images include a [SynthID watermark](https://ai.google.dev/responsible/docs/safeguards/synthid). ## Image generation (text-to-image) {% id="image-generation-text-to-image" %} {% tabs %} {% tab label="Python" %} ```python from google import genai from PIL import Image import base64 client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input="Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme", ) with open("generated_image.png", "wb") as f: f.write(base64.b64decode(interaction.output_image.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const prompt = "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"; const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: prompt, }); const generatedImage = interaction.output_image; if (generatedImage) { if (generatedImage && generatedImage.data) { const buffer = Buffer.from(generatedImage.data, "base64"); fs.writeFileSync("gemini-native-image.png", buffer); } console.log("Image saved as gemini-native-image.png"); } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Base64; Client client = new Client(); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme")) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.outputImage().isPresent() && interaction.outputImage().get().data().isPresent()) { byte[] imageBytes = Base64.getDecoder().decode(interaction.outputImage().get().data().get()); Files.write(Paths.get("generated_image.png"), imageBytes); } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"), }), }) if err != nil { log.Fatal(err) } if res.Interaction.OutputImage != nil && res.Interaction.OutputImage.Data != nil { imageBytes, err := base64.StdEncoding.DecodeString(*res.Interaction.OutputImage.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("generated_image.png", imageBytes, 0644); err != nil { log.Fatal(err) } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -H "Api-Revision: 2026-05-20" \ -d '{ "model": "gemini-nano-banana-2.1", "input": [ {"type": "text", "text": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"} ] }' ``` {% /tab %} {% /tabs %} You can retrieve generated image data by using the `interaction.output_image` property, which returns the last generated image block. {% callout type="note" %} Note: For complex, interleaved text-and-image outputs (such as stories containing illustrations), convenience properties will not capture all parts. You must manually iterate over the steps instead-see [Interleaved text and images](/docs/image-generation#interleaved-output) for an example. {% /callout %} ## Image editing (text-and-image-to-image) {% id="gemini-image-editing" %} **Reminder**: Make sure you have the necessary rights to any images you upload. Don't generate content that infringe on others' rights, including videos or images that deceive, harass, or harm. Your use of this generative AI service is subject to our [Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy). Provide an image and use text prompts to add, remove, or modify elements, change the style, or adjust the color grading. The following example demonstrates uploading `base64` encoded images. For multiple images, larger payloads, and supported MIME types, check the [Image understanding](/docs/image-understanding) page. {% tabs %} {% tab label="Python" %} ```python from google import genai from PIL import Image import base64 client = genai.Client() with open("/path/to/cat_image.png", "rb") as f: image_bytes = f.read() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=[ { "type": "text", "text": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme" }, { "type": "image", "data": base64.b64encode(image_bytes).decode('utf-8'), "mime_type": "image/png" } ], ) with open("generated_image.png", "wb") as f: f.write(base64.b64decode(interaction.output_image.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const imagePath = "path/to/cat_image.png"; const imageData = fs.readFileSync(imagePath); const base64Image = imageData.toString("base64"); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: [ { type: "text", text: "Create a picture of my cat eating a nano-banana in a" + "fancy restaurant under the Gemini constellation" }, { type: "image", mime_type: "image/png", data: base64Image }, ], }); const generatedImage = interaction.output_image; if (generatedImage) { if (generatedImage && generatedImage.data) { const buffer = Buffer.from(generatedImage.data, "base64"); fs.writeFileSync("gemini-native-image.png", buffer); } console.log("Image saved as gemini-native-image.png"); } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageContentMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; import java.util.List; Client client = new Client(); byte[] inputBytes = Files.readAllBytes(Paths.get("/path/to/cat_image.png")); String base64Image = Base64.getEncoder().encodeToString(inputBytes); Content textContent = TextContent.builder() .text("Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme") .build(); Content imageContent = ImageContent.builder() .data(base64Image) .mimeType(ImageContentMimeType.IMAGE_PNG) .build(); List contents = Arrays.asList(textContent, imageContent); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.ofContent(contents)) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.outputImage().isPresent() && interaction.outputImage().get().data().isPresent()) { byte[] outputBytes = Base64.getDecoder().decode(interaction.outputImage().get().data().get()); Files.write(Paths.get("generated_image.png"), outputBytes); } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } inputBytes, err := os.ReadFile("/path/to/cat_image.png") if err != nil { log.Fatal(err) } base64Image := base64.StdEncoding.EncodeToString(inputBytes) res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput([]interactions.Content{ interactions.NewContent(interactions.TextContent{ Text: "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme", }), interactions.NewContent(interactions.ImageContent{ Data: genai.Ptr(base64Image), MimeType: interactions.ImageContentMimeTypeImagePng.ToPointer(), }), }), }), }) if err != nil { log.Fatal(err) } if res.Interaction.OutputImage != nil && res.Interaction.OutputImage.Data != nil { outputBytes, err := base64.StdEncoding.DecodeString(*res.Interaction.OutputImage.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("generated_image.png", outputBytes, 0644); err != nil { log.Fatal(err) } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -H "Api-Revision: 2026-05-20" \ -d "{ \"model\": \"gemini-nano-banana-2.1\", \"input\": [ {\"type\": \"text\", \"text\": \"Create a picture of my cat eating a nano-banana in a fancy restaurant under the Gemini constellation\"}, { \"type\": \"image\", \"mime_type\": \"image/jpeg\", \"data\": \"[BASE64_IMAGE_DATA]\" } ] }" ``` {% /tab %} {% /tabs %} ### Multi-turn image editing {% id="multi-turn-image-editing" %} Keep generating and editing images conversationally. Multi-turn conversation is the recommended way to iterate on images. The following example shows a prompt to generate an infographic about photosynthesis. {% tabs %} {% tab label="Python" %} ```python from google import genai import base64 client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input="Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plant's favorite food. Show the \"ingredients\" (sunlight, water, CO2) and the \"finished dish\" (sugar/energy). The style should be like a page from a colorful kids' cookbook, suitable for a 4th grader.", tools=[{"type": "google_search"}], ) with open("photosynthesis.png", "wb") as f: f.write(base64.b64decode(interaction.output_image.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; const ai = new GoogleGenAI({}); async function main() { const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plant's favorite food. Show the \"ingredients\" (sunlight, water, CO2) and the \"finished dish\" (sugar/energy). The style should be like a page from a colorful kids' cookbook, suitable for a 4th grader.", tools: [{"type": "google_search"}], }); const generatedImage = interaction.output_image; if (generatedImage) { if (generatedImage && generatedImage.data) { const buffer = Buffer.from(generatedImage.data, "base64"); fs.writeFileSync("photosynthesis.png", buffer); } console.log("Image saved as photosynthesis.png"); } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.GoogleSearch; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; Client client = new Client(); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plant's favorite food. Show the \"ingredients\" (sunlight, water, CO2) and the \"finished dish\" (sugar/energy). The style should be like a page from a colorful kids' cookbook, suitable for a 4th grader.")) .tools(Arrays.asList(new GoogleSearch())) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.outputImage().isPresent() && interaction.outputImage().get().data().isPresent()) { byte[] imageBytes = Base64.getDecoder().decode(interaction.outputImage().get().data().get()); Files.write(Paths.get("photosynthesis.png"), imageBytes); } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(`Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plant's favorite food. Show the "ingredients" (sunlight, water, CO2) and the "finished dish" (sugar/energy). The style should be like a page from a colorful kids' cookbook, suitable for a 4th grader.`), Tools: []interactions.Tool{ interactions.NewTool(interactions.GoogleSearch{}), }, }), }) if err != nil { log.Fatal(err) } if res.Interaction.OutputImage != nil && res.Interaction.OutputImage.Data != nil { imageBytes, err := base64.StdEncoding.DecodeString(*res.Interaction.OutputImage.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("photosynthesis.png", imageBytes, 0644); err != nil { log.Fatal(err) } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -H "Api-Revision: 2026-05-20" \ -d '{ "model": "gemini-nano-banana-2.1", "input": [ {"type": "text", "text": "Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plants favorite food. Show the \"ingredients\" (sunlight, water, CO2) and the \"finished dish\" (sugar/energy). The style should be like a page from a colorful kids cookbook, suitable for a 4th grader."} ], "tools": [{"type": "google_search"}] }' ``` {% /tab %} {% /tabs %} ![](https://www.gstatic.com/cloud-cms/bb7eae3c8034fd8aded280176d387543.png)You can then use the `previous_interaction_id` to change the language on the graphic to Spanish. {% tabs %} {% tab label="Python" %} ```python interaction_2 = client.interactions.create( model="gemini-nano-banana-2.1", input="Update this infographic to be in Spanish. Do not change any other elements of the image.", previous_interaction_id=interaction.id, response_format={ "type": "image", "mime_type": "image/jpeg", "aspect_ratio": "16:9", "image_size": "2K" }, ) generated_image = interaction_2.output_image if generated_image: with open("photosynthesis_spanish.png", "wb") as f: f.write(base64.b64decode(generated_image.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript const interaction2 = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "Update this infographic to be in Spanish. Do not change any other elements of the image.", previous_interaction_id: interaction.id, response_format: { type: "image", mime_type: "image/png", aspect_ratio: "16:9", image_size: "2K" }, }); const generatedImage = interaction2.output_image; if (generatedImage) { if (generatedImage && generatedImage.data) { const buffer = Buffer.from(generatedImage.data, "base64"); fs.writeFileSync("photosynthesis_spanish.png", buffer); } } ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat; import com.google.genai.gaos.models.interactions.GoogleSearch; import com.google.genai.gaos.models.interactions.ImageResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormatAspectRatio; import com.google.genai.gaos.models.interactions.ImageResponseFormatImageSize; import com.google.genai.gaos.models.interactions.ImageResponseFormatMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ResponseFormat; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; Client client = new Client(); CreateModelInteraction turn1Params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plant's favorite food.")) .tools(Arrays.asList(new GoogleSearch())) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(turn1Params)).interaction().get(); CreateModelInteractionResponseFormat format = CreateModelInteractionResponseFormat.of( ResponseFormat.of( ImageResponseFormat.builder() .mimeType(ImageResponseFormatMimeType.IMAGE_JPEG) .aspectRatio(ImageResponseFormatAspectRatio.of("16:9")) .imageSize(ImageResponseFormatImageSize.TWO_K) .build())); CreateModelInteraction turn2Params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "Update this infographic to be in Spanish. Do not change any other elements of the image.")) .previousInteractionId(interaction.id().orElse("")) .responseFormat(format) .build(); Interaction interaction2 = client.interactions.create(CreateInteractionRequestBody.of(turn2Params)).interaction().get(); if (interaction2.outputImage().isPresent() && interaction2.outputImage().get().data().isPresent()) { byte[] imageBytes = Base64.getDecoder().decode(interaction2.outputImage().get().data().get()); Files.write(Paths.get("photosynthesis_spanish.png"), imageBytes); } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } res1, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plant's favorite food."), Tools: []interactions.Tool{ interactions.NewTool(interactions.GoogleSearch{}), }, }), }) if err != nil { log.Fatal(err) } format := interactions.NewCreateModelInteractionResponseFormat( interactions.NewResponseFormat(interactions.ImageResponseFormat{ MimeType: interactions.ImageResponseFormatMimeTypeImageJpeg.ToPointer(), AspectRatio: interactions.ImageResponseFormatAspectRatio("16:9").ToPointer(), ImageSize: interactions.ImageResponseFormatImageSizeTwoK.ToPointer(), }), ) res2, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("Update this infographic to be in Spanish. Do not change any other elements of the image."), PreviousInteractionID: res1.Interaction.ID, ResponseFormat: genai.Ptr(format), }), }) if err != nil { log.Fatal(err) } if res2.Interaction.OutputImage != nil && res2.Interaction.OutputImage.Data != nil { imageBytes, err := base64.StdEncoding.DecodeString(*res2.Interaction.OutputImage.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("photosynthesis_spanish.png", imageBytes, 0644); err != nil { log.Fatal(err) } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -H "Api-Revision: 2026-05-20" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "Update this infographic to be in Spanish. Do not change any other elements of the image.", "previous_interaction_id": "[PREVIOUS_INTERACTION_ID]", "response_format": { "type": "image", "mime_type": "image/jpeg", "aspect_ratio": "16:9", "image_size": "2K" } }' ``` {% /tab %} {% /tabs %} ![](https://www.gstatic.com/cloud-cms/b435b5da9f72aebf268a1d821a46bd3a.png)## Features of Nano Banana {% id="gemini-3-capabilities" %} Nano Banana models offer state-of-the-art image generation and editing. Gemini Nano Banana 2.1 and Gemini 3.1 Flash Image are optimized for speed and high-volume use-cases, and Gemini 3 Pro Image is optimized for professional asset production. Designed to tackle the most challenging workflows through advanced reasoning, they excel at complex, multi-turn creation and modification tasks. - **High-resolution output**: Built-in generation capabilities for 1K, 2K, and 4K visuals. - **Gemini 3.1 Flash Image** adds the smaller 512px (0.5K) resolution (not supported on Gemini Nano Banana 2.1). - **Advanced text rendering**: Capable of generating legible, stylized text for infographics, menus, diagrams, and marketing assets. - **Grounding with Google Search**: The model can use Google Search as a tool to verify facts and generate imagery based on real-time data (e.g., current weather maps, stock charts, recent events). - **Gemini Nano Banana 2.1 and Gemini 3.1 Flash Image** add the integration of Google Image Search Grounding alongside Web Search. - **Thinking mode**: The model utilizes a "thinking" process to reason through complex prompts. It generates interim "thought images" (visible in the backend but not charged) to refine the composition before producing the final high-quality output. - **Up to 14 reference images**: Mix up to 14 reference images to produce the final image. - **New aspect ratios**: Gemini Nano Banana 2.1 and Gemini 3.1 Flash Image add 1:4, 4:1, 1:8, and 8:1 [aspect ratios](/docs/image-generation#aspect-ratios-and-image-size). ### Use up to 14 reference images {% id="use-14-images" %} Nano Banana models allow you to mix up to 14 reference images. These 14 images can include the following: | Gemini Nano Banana 2.1 & Gemini 3.1 Flash Image | Gemini 3 Pro Image | | :--- | :--- | | Up to 10 images of objects with high-fidelity to include in the final image | Up to 6 images of objects with high-fidelity to include in the final image | | Up to 4 images of characters to maintain character consistency | Up to 5 images of characters to maintain character consistency | | N/A | Up to 3 images to be used as style references | {% tabs %} {% tab label="Python" %} ```python from google import genai from google.genai import types from PIL import Image import base64 prompt = "An office group photo of these people, they are making funny faces." client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=[ { "type": "text", "text": prompt, }, { "type": "image", "data": base64.b64encode(image_bytes).decode('utf-8'), "mime_type": "image/png" }, { "type": "image", "data": base64.b64encode(image_bytes).decode('utf-8'), "mime_type": "image/png" }, { "type": "image", "data": base64.b64encode(image_bytes).decode('utf-8'), "mime_type": "image/png" }, { "type": "image", "data": base64.b64encode(image_bytes).decode('utf-8'), "mime_type": "image/png" }, { "type": "image", "data": base64.b64encode(image_bytes).decode('utf-8'), "mime_type": "image/png" }, ], response_format={ "type": "image", "aspect_ratio": "5:4", "image_size": "2K" }, ) with open("office.png", "wb") as f: f.write(base64.b64decode(interaction.output_image.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: [ { type: "text", text: "An office group photo of these people, they are making funny faces.", }, { type: "image", mime_type: "image/jpeg", data: base64ImageFile1 }, { type: "image", mime_type: "image/jpeg", data: base64ImageFile2 }, { type: "image", mime_type: "image/jpeg", data: base64ImageFile3 }, { type: "image", mime_type: "image/jpeg", data: base64ImageFile4 }, { type: "image", mime_type: "image/jpeg", data: base64ImageFile5 }, ], response_format: { type: "image", aspect_ratio: "5:4", image_size: "2K", }, }); if (interaction.output_image && interaction.output_image.data) { const buffer = Buffer.from(interaction.output_image.data, 'base64'); fs.writeFileSync('office.png', buffer); } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageContentMimeType; import com.google.genai.gaos.models.interactions.ImageResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormatAspectRatio; import com.google.genai.gaos.models.interactions.ImageResponseFormatImageSize; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ResponseFormat; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; import java.util.List; String prompt = "An office group photo of these people, they are making funny faces."; byte[] imageBytes = Files.readAllBytes(Paths.get("/path/to/person.png")); String base64Image = Base64.getEncoder().encodeToString(imageBytes); Content textContent = TextContent.builder().text(prompt).build(); Content imageContent = ImageContent.builder() .data(base64Image) .mimeType(ImageContentMimeType.IMAGE_PNG) .build(); List contents = Arrays.asList( textContent, imageContent, imageContent, imageContent, imageContent, imageContent); CreateModelInteractionResponseFormat format = CreateModelInteractionResponseFormat.of( ResponseFormat.of( ImageResponseFormat.builder() .aspectRatio(ImageResponseFormatAspectRatio.of("5:4")) .imageSize(ImageResponseFormatImageSize.TWO_K) .build())); Client client = new Client(); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.ofContent(contents)) .responseFormat(format) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.outputImage().isPresent() && interaction.outputImage().get().data().isPresent()) { byte[] outBytes = Base64.getDecoder().decode(interaction.outputImage().get().data().get()); Files.write(Paths.get("office.png"), outBytes); } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } prompt := "An office group photo of these people, they are making funny faces." imageBytes, err := os.ReadFile("/path/to/person.png") if err != nil { log.Fatal(err) } base64Image := base64.StdEncoding.EncodeToString(imageBytes) textContent := interactions.NewContent(interactions.TextContent{ Text: prompt, }) imageContent := interactions.NewContent(interactions.ImageContent{ Data: genai.Ptr(base64Image), MimeType: interactions.ImageContentMimeTypeImagePng.ToPointer(), }) contents := []interactions.Content{ textContent, imageContent, imageContent, imageContent, imageContent, imageContent, } format := interactions.NewCreateModelInteractionResponseFormat( interactions.NewResponseFormat(interactions.ImageResponseFormat{ AspectRatio: interactions.ImageResponseFormatAspectRatio("5:4").ToPointer(), ImageSize: interactions.ImageResponseFormatImageSizeTwoK.ToPointer(), }), ) res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(contents), ResponseFormat: genai.Ptr(format), }), }) if err != nil { log.Fatal(err) } if res.Interaction.OutputImage != nil && res.Interaction.OutputImage.Data != nil { outBytes, err := base64.StdEncoding.DecodeString(*res.Interaction.OutputImage.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("office.png", outBytes, 0644); err != nil { log.Fatal(err) } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -H "Api-Revision: 2026-05-20" \ -d "{ \"model\": \"gemini-nano-banana-2.1\", \"input\": [ {\"type\": \"text\", \"text\": \"An office group photo of these people, they are making funny faces.\"}, {\"type\": \"image\", \"mime_type\": \"image/png\", \"data\": \"[BASE64_DATA_IMG_1]\"}, {\"type\": \"image\", \"mime_type\": \"image/png\", \"data\": \"[BASE64_DATA_IMG_2]\"}, {\"type\": \"image\", \"mime_type\": \"image/png\", \"data\": \"[BASE64_DATA_IMG_3]\"}, {\"type\": \"image\", \"mime_type\": \"image/png\", \"data\": \"[BASE64_DATA_IMG_4]\"}, {\"type\": \"image\", \"mime_type\": \"image/png\", \"data\": \"[BASE64_DATA_IMG_5]\"} ], \"response_format\": { \"type\": \"image\", \"aspect_ratio\": \"5:4\", \"image_size\": \"2K\" } }" ``` {% /tab %} {% /tabs %} ![](https://www.gstatic.com/cloud-cms/e4b16a85c6cedde829bc7532c456fe5a.jpeg)### Grounding with Google Search {% id="use-with-grounding" %} Use the [Google Search tool](/docs/google-search) to generate images based on real-time information, such as weather forecasts, stock charts, or recent events. Note that when using Grounding with Google Search with image generation, image-based search results are not passed to the generation model and are excluded from the response (see [Grounding with Google Image Search](/docs/image-generation#image-search)) {% tabs %} {% tab label="Python" %} ```python from google import genai from google.genai import types import base64 prompt = "Visualize the current weather forecast for the next 5 days in San Francisco as a clean, modern weather chart. Add a visual on what I should wear each day" client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=prompt, tools=[{"type": "google_search"}], response_format={ "type": "image", "mime_type": "image/jpeg", "aspect_ratio": "16:9" }, ) with open("weather.png", "wb") as f: f.write(base64.b64decode(interaction.output_image.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "Visualize the current weather forecast for the next 5 days in San Francisco as a clean, modern weather chart. Add a visual on what I should wear each day", tools: [{"type": "google_search"}], response_format: { type: "image", mime_type: "image/png", aspect_ratio: "16:9", image_size: "2K" }, }); if (interaction.output_image && interaction.output_image.data) { const buffer = Buffer.from(interaction.output_image.data, 'base64'); fs.writeFileSync('weather.png', buffer); } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat; import com.google.genai.gaos.models.interactions.GoogleSearch; import com.google.genai.gaos.models.interactions.ImageResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormatAspectRatio; import com.google.genai.gaos.models.interactions.ImageResponseFormatMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ResponseFormat; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; String prompt = "Visualize the current weather forecast for the next 5 days in San Francisco as a clean, modern weather chart. Add a visual on what I should wear each day"; Client client = new Client(); CreateModelInteractionResponseFormat format = CreateModelInteractionResponseFormat.of( ResponseFormat.of( ImageResponseFormat.builder() .mimeType(ImageResponseFormatMimeType.IMAGE_JPEG) .aspectRatio(ImageResponseFormatAspectRatio.of("16:9")) .build())); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.of(prompt)) .tools(Arrays.asList(new GoogleSearch())) .responseFormat(format) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.outputImage().isPresent() && interaction.outputImage().get().data().isPresent()) { byte[] imageBytes = Base64.getDecoder().decode(interaction.outputImage().get().data().get()); Files.write(Paths.get("weather.png"), imageBytes); } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } prompt := "Visualize the current weather forecast for the next 5 days in San Francisco as a clean, modern weather chart. Add a visual on what I should wear each day" format := interactions.NewCreateModelInteractionResponseFormat( interactions.NewResponseFormat(interactions.ImageResponseFormat{ MimeType: interactions.ImageResponseFormatMimeTypeImageJpeg.ToPointer(), AspectRatio: interactions.ImageResponseFormatAspectRatio("16:9").ToPointer(), }), ) res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(prompt), Tools: []interactions.Tool{ interactions.NewTool(interactions.GoogleSearch{}), }, ResponseFormat: genai.Ptr(format), }), }) if err != nil { log.Fatal(err) } if res.Interaction.OutputImage != nil && res.Interaction.OutputImage.Data != nil { imageBytes, err := base64.StdEncoding.DecodeString(*res.Interaction.OutputImage.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("weather.png", imageBytes, 0644); err != nil { log.Fatal(err) } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -H "Api-Revision: 2026-05-20" \ -d '{ "model": "gemini-nano-banana-2.1", "input": [ {"type": "text", "text": "Visualize the current weather forecast for the next 5 days in San Francisco as a clean, modern weather chart. Add a visual on what I should wear each day"} ], "tools": [{"type": "google_search"}], "response_format": { "type": "image", "mime_type": "image/jpeg", "aspect_ratio": "16:9" } }' ``` {% /tab %} {% /tabs %} ![](https://www.gstatic.com/cloud-cms/3444f386f283ac68b9d97cfe37c2f588.png)The response includes `google_search_call` and `google_search_result` steps, along with inline `url_citation` annotations on the text step: - **`google_search_result`**: Contains `search_suggestions`, an HTML snippet for rendering search suggestions in your UI. - **`url_citation` annotations**: Inline citations on the text step linking parts of the response to their web sources. ### Grounding with Google Search for Images (Nano Banana 2.1 and 3.1 Flash) {% id="image-search" %} {% callout type="note" %} Note: This feature is only available for the Gemini Nano Banana 2.1 and Gemini 3.1 Flash Image models. {% /callout %} Grounding with Google Image Search allows models to use web images retrieved via Google Image Search as visual context for image generation. Image Search is a new search type within the existing Grounding with Google Search tool, functioning alongside standard [Web Search](/docs/image-generation#use-with-grounding). To enable Image Search, configure the `google_search` tool in your API request and specify `image_search` within the `search_types` array. Image Search can be used independently or together with Web Search. {% tabs %} {% tab label="Python" %} ```python from google import genai client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input="A detailed painting of a Timareta butterfly resting on a flower", tools=[{ "type": "google_search", "search_types": ["web_search", "image_search"] }] ) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "A detailed painting of a Timareta butterfly resting on a flower", tools: [{ "type": "google_search", "search_types": ["web_search", "image_search"] }] }); } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.GoogleSearch; import com.google.genai.gaos.models.interactions.GoogleSearchSearchType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.util.Arrays; Client client = new Client(); GoogleSearch searchTool = GoogleSearch.builder() .searchTypes( Arrays.asList( GoogleSearchSearchType.WEB_SEARCH, GoogleSearchSearchType.IMAGE_SEARCH)) .build(); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "A detailed painting of a Timareta butterfly resting on a flower")) .tools(Arrays.asList(searchTool)) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "log" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } searchTool := interactions.GoogleSearch{ SearchTypes: []interactions.GoogleSearchSearchType{ interactions.GoogleSearchSearchTypeWebSearch, interactions.GoogleSearchSearchTypeImageSearch, }, } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("A detailed painting of a Timareta butterfly resting on a flower"), Tools: []interactions.Tool{ interactions.NewTool(searchTool), }, }), }) if err != nil { log.Fatal(err) } _ = res } ``` {% /tab %} {% tab label="REST" %} ```shell curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -H "Api-Revision: 2026-05-20" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "A detailed painting of a Timareta butterfly resting on a flower", "tools": [{"type": "google_search", "search_types": ["web_search", "image_search"]}] }' ``` {% /tab %} {% /tabs %} **Display requirements** When you use Image Search within Grounding with Google Search, you must display the `search_suggestions` from the `google_search_result` step. Full usage requirements are detailed in the [Terms of Service](/docs/terms#grounding-with-google-search). **Response** For grounded responses using image search, the API returns inline citations and attribution metadata as part of the response steps: * **`url_citation` annotations**: Inline citations on the text content block within `model_output`, linking the generated content to its source. * **`google_search_result`**: Contains `search_suggestions`, an HTML snippet for rendering search suggestions in your UI. ### Video-to-image generation (Nano Banana 2.1, 3.1 Flash, and 3.1 Flash Lite) {% id="video-to-image" %} {% callout type="note" %} Note: This feature is only available for the Gemini Nano Banana 2.1, Gemini 3.1 Flash Image, and Gemini 3.1 Flash Lite Image models. {% /callout %} Video-to-image generation allows you to generate new images using a video's context as a multimodal reference. This is useful for creating high-quality video thumbnails, cinematic posters, summary infographics, or new artwork inspired by a video scene. During generation, the model analyzes the video frames in context to extract visual themes and key events, then uses them alongside your text prompt to synthesize the output image. You can pass public [YouTube URLs](/docs/video-understanding#youtube) directly in your API request or upload local video files using the [Files API](/docs/files). {% tabs %} {% tab label="Python" %} ```python from google import genai from google.genai import types import base64 client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=[ { "type": "video", "uri": "https://www.youtube.com/watch?v=UTdfxFyOQTI", "mime_type": "video/mp4" }, {"type": "text", "text": "Generate a poster image that captures the key themes of this video."} ], response_format={"type": "image", "aspect_ratio": "16:9"} ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("video_poster.png", "wb") as f: f.write(base64.b64decode(content_block.data)) print("Image saved as video_poster.png") ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: [ { type: "video", uri: "https://www.youtube.com/watch?v=UTdfxFyOQTI", mime_type: "video/mp4" }, { type: "text", text: "Generate a poster image that captures the key themes of this video." } ], response_format: { type: "image", aspect_ratio: "16:9" } }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("video_poster.png", buffer); } console.log("Image saved as video_poster.png"); } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormatAspectRatio; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.ResponseFormat; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.interactions.VideoContent; import com.google.genai.gaos.models.interactions.VideoContentMimeType; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; import java.util.List; Client client = new Client(); Content videoContent = VideoContent.builder() .uri("https://www.youtube.com/watch?v=UTdfxFyOQTI") .mimeType(VideoContentMimeType.VIDEO_MP4) .build(); Content textContent = TextContent.builder() .text("Generate a poster image that captures the key themes of this video.") .build(); List contents = Arrays.asList(videoContent, textContent); CreateModelInteractionResponseFormat format = CreateModelInteractionResponseFormat.of( ResponseFormat.of( ImageResponseFormat.builder() .aspectRatio(ImageResponseFormatAspectRatio.of("16:9")) .build())); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.ofContent(contents)) .responseFormat(format) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content block : outputStep.content().get()) { if (block instanceof TextContent) { System.out.println(((TextContent) block).text().orElse("")); } else if (block instanceof ImageContent) { ImageContent img = (ImageContent) block; if (img.data().isPresent()) { byte[] imgBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("video_poster.png"), imgBytes); System.out.println("Image saved as video_poster.png"); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } contents := []interactions.Content{ interactions.NewContent(interactions.VideoContent{ URI: genai.Ptr("https://www.youtube.com/watch?v=UTdfxFyOQTI"), MimeType: interactions.VideoContentMimeTypeVideoMp4.ToPointer(), }), interactions.NewContent(interactions.TextContent{ Text: "Generate a poster image that captures the key themes of this video.", }), } format := interactions.NewCreateModelInteractionResponseFormat( interactions.NewResponseFormat(interactions.ImageResponseFormat{ AspectRatio: interactions.ImageResponseFormatAspectRatio("16:9").ToPointer(), }), ) res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(contents), ResponseFormat: genai.Ptr(format), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, block := range step.ModelOutputStep.Content { if block.TextContent != nil { fmt.Println(block.TextContent.Text) } else if block.ImageContent != nil && block.ImageContent.Data != nil { imgBytes, err := base64.StdEncoding.DecodeString(*block.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("video_poster.png", imgBytes, 0644); err != nil { log.Fatal(err) } fmt.Println("Image saved as video_poster.png") } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -H "Api-Revision: 2026-05-20" \ -d '{ "model": "gemini-nano-banana-2.1", "input": [ { "type": "video", "uri": "https://www.youtube.com/watch?v=UTdfxFyOQTI", "mime_type": "video/mp4" }, { "type": "text", "text": "Generate a poster image that captures the key themes of this video." } ], "response_format": { "type": "image", "aspect_ratio": "16:9" } }' ``` {% /tab %} {% /tabs %} ![](https://www.gstatic.com/cloud-cms/f0d79a97f2742cf79b96cc961e8625bb.jpg)### Generate images up to 4K resolution {% id="generate-4k-images" %} Gemini 3 image models generate 1K images by default but can also output 2K, 4K, and 512px (05.K) (Gemini 3.1 Flash Image only) images. To generate higher resolution assets, specify the `image_size` in the `response_format`. You must use an uppercase 'K' (e.g. 512px (05.K), 1K, 2K, 4K). Lowercase parameters (e.g., 1k) will be rejected. {% tabs %} {% tab label="Python" %} ```python from google import genai from google.genai import types import base64 prompt = "Da Vinci style anatomical sketch of a dissected Monarch butterfly. Detailed drawings of the head, wings, and legs on textured parchment with notes in English." client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=prompt, response_format={ "type": "image", "mime_type": "image/jpeg", "aspect_ratio": "1:1", "image_size": "1K" }, ) print(interaction.output_text) with open("butterfly.png", "wb") as f: f.write(base64.b64decode(interaction.output_image.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "Da Vinci style anatomical sketch of a dissected Monarch butterfly. Detailed drawings of the head, wings, and legs on textured parchment with notes in English.", response_format: { type: "image", mime_type: "image/png", aspect_ratio: "1:1", image_size: "1K", }, }); console.log(interaction.output_text); if (interaction.output_image && interaction.output_image.data) { const buffer = Buffer.from(interaction.output_image.data, 'base64'); fs.writeFileSync('butterfly.png', buffer); } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormatAspectRatio; import com.google.genai.gaos.models.interactions.ImageResponseFormatImageSize; import com.google.genai.gaos.models.interactions.ImageResponseFormatMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ResponseFormat; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Base64; String prompt = "Da Vinci style anatomical sketch of a dissected Monarch butterfly. Detailed drawings of the head, wings, and legs on textured parchment with notes in English."; Client client = new Client(); CreateModelInteractionResponseFormat format = CreateModelInteractionResponseFormat.of( ResponseFormat.of( ImageResponseFormat.builder() .mimeType(ImageResponseFormatMimeType.IMAGE_JPEG) .aspectRatio(ImageResponseFormatAspectRatio.of("1:1")) .imageSize(ImageResponseFormatImageSize.ONE_K) .build())); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.of(prompt)) .responseFormat(format) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); System.out.println(interaction.outputText().orElse("")); if (interaction.outputImage().isPresent() && interaction.outputImage().get().data().isPresent()) { byte[] imageBytes = Base64.getDecoder().decode(interaction.outputImage().get().data().get()); Files.write(Paths.get("butterfly.png"), imageBytes); } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } prompt := "Da Vinci style anatomical sketch of a dissected Monarch butterfly. Detailed drawings of the head, wings, and legs on textured parchment with notes in English." format := interactions.NewCreateModelInteractionResponseFormat( interactions.NewResponseFormat(interactions.ImageResponseFormat{ MimeType: interactions.ImageResponseFormatMimeTypeImageJpeg.ToPointer(), AspectRatio: interactions.ImageResponseFormatAspectRatio("1:1").ToPointer(), ImageSize: interactions.ImageResponseFormatImageSizeOneK.ToPointer(), }), ) res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(prompt), ResponseFormat: genai.Ptr(format), }), }) if err != nil { log.Fatal(err) } if res.Interaction.OutputText != nil { fmt.Println(*res.Interaction.OutputText) } if res.Interaction.OutputImage != nil && res.Interaction.OutputImage.Data != nil { imageBytes, err := base64.StdEncoding.DecodeString(*res.Interaction.OutputImage.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("butterfly.png", imageBytes, 0644); err != nil { log.Fatal(err) } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -H "Api-Revision: 2026-05-20" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "Da Vinci style anatomical sketch of a dissected Monarch butterfly. Detailed drawings of the head, wings, and legs on textured parchment with notes in English.", "response_format": { "type": "image", "mime_type": "image/jpeg", "aspect_ratio": "1:1", "image_size": "1K" } }' ``` {% /tab %} {% /tabs %} The following is an example image generated from this prompt: ![](https://www.gstatic.com/cloud-cms/c111455910e372aa2c46d7cb7b0c5d85.png)### Thinking Process {% id="thinking-process" %} Gemini 3 image models are thinking models that use a reasoning process ("Thinking") for complex prompts. This feature is enabled by default and cannot be disabled in the API. To learn more about the thinking process, see the [Gemini Thinking](/docs/thinking) guide. The model generates up to two interim images to test composition and logic. The last image within Thinking is also the final rendered image. You can check the thoughts that lead to the final image being produced. {% tabs %} {% tab label="Python" %} ```python for step in interaction.steps: if step.type == "thought": for content_block in step.summary: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": image = Image.open(io.BytesIO(base64.b64decode(content_block.data))) image.show() ``` {% /tab %} {% tab label="JavaScript" %} ```javascript for (const step of interaction.steps) { if (step.type === "thought") { for (const contentBlock of step.summary) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("thought_image.png", buffer); } } } } } ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.interactions.ThoughtStep; import com.google.genai.gaos.models.interactions.ThoughtSummaryContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Base64; Client client = new Client(); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "A futuristic city built inside a giant glass bottle floating in space")) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ThoughtStep) { ThoughtStep thoughtStep = (ThoughtStep) step; if (thoughtStep.summary().isPresent()) { for (ThoughtSummaryContent contentBlock : thoughtStep.summary().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] imgBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("thought_image.png"), imgBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("A futuristic city built inside a giant glass bottle floating in space"), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ThoughtStep != nil { for _, contentBlock := range step.ThoughtStep.Summary { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { imgBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("thought_image.png", imgBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% /tabs %} #### Interleaved text and images {% id="interleaved-output" %} While standard image generation models only output images, some advanced Gemini 3 models (such as `gemini-3-pro-image`) can generate interleaved content-like stories or instructional guides containing both text blocks and illustrations inside the same response. Because the output is complex and interleaved, convenience properties like `.output_image` or `.output_text` will not capture the full sequence. To access and save interleaved content, you must manually iterate over `steps`: {% tabs %} {% tab label="Python" %} ```python interaction = client.interactions.create( model="gemini-3-pro-image", input="Write the story of the lifecycle of a monarch butterfly, interleave illustrations", ) image_counter = 1 for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": filename = f"butterfly_lifecycle_{image_counter}.png" with open(filename, "wb") as f: f.write(base64.b64decode(content_block.data)) print(f"\n[Saved illustration: {filename}]\n") image_counter += 1 ``` {% /tab %} {% tab label="JavaScript" %} ```javascript const interaction = await ai.interactions.create({ model: "gemini-3-pro-image", input: "Write the story of the lifecycle of a monarch butterfly, interleave illustrations", }); let imageCounter = 1; for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { const buffer = Buffer.from(contentBlock.data, "base64"); const filename = `butterfly_lifecycle_${imageCounter}.png`; fs.writeFileSync(filename, buffer); console.log(`\n[Saved illustration: ${filename}]\n`); imageCounter++; } } } } ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Base64; Client client = new Client(); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-3-pro-image")) .input( InteractionsInput.of( "Write the story of the lifecycle of a monarch butterfly, interleave illustrations")) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); int imageCounter = 1; if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { String filename = String.format("butterfly_lifecycle_%d.png", imageCounter); byte[] imgBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get(filename), imgBytes); System.out.printf("%n[Saved illustration: %s]%n", filename); imageCounter++; } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-3-pro-image"), Input: interactions.NewInteractionsInput("Write the story of the lifecycle of a monarch butterfly, interleave illustrations"), }), }) if err != nil { log.Fatal(err) } imageCounter := 1 for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { filename := fmt.Sprintf("butterfly_lifecycle_%d.png", imageCounter) imgBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile(filename, imgBytes, 0644); err != nil { log.Fatal(err) } fmt.Printf("\n[Saved illustration: %s]\n", filename) imageCounter++ } } } } } ``` {% /tab %} {% /tabs %} #### Controlling thinking levels {% id="thinking-levels" %} With Gemini Nano Banana 2.1, Gemini 3.1 Flash Image, and Gemini 3.1 Flash Lite Image, you can control the amount of thinking the model uses to balance quality and latency: | Model | Supported thinking levels | Default | | :--- | :--- | :--- | | **Gemini Nano Banana 2.1** | `minimal`, `medium`, `high` | `medium` | | **Gemini 3.1 Flash Image** | `minimal`, `high` | `minimal` | | **Gemini 3.1 Flash Lite Image** | `minimal`, `high` | `minimal` | {% tabs %} {% tab label="Python" %} ```python from google import genai from PIL import Image import base64 import io client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input="A futuristic city built inside a giant glass bottle floating in space", generation_config={"thinking_level": "high"}, ) print(interaction.output_text) image = Image.open(io.BytesIO(base64.b64decode(interaction.output_image.data))) image.show() ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "A futuristic city built inside a giant glass bottle floating in space", generation_config: { thinking_level: "high" }, }); console.log(interaction.output_text); if (interaction.output_image && interaction.output_image.data) { const buffer = Buffer.from(interaction.output_image.data, 'base64'); fs.writeFileSync('image.png', buffer); } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.GenerationConfig; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ThinkingLevel; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Base64; Client client = new Client(); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "A futuristic city built inside a giant glass bottle floating in space")) .generationConfig(GenerationConfig.builder().thinkingLevel(ThinkingLevel.HIGH).build()) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); System.out.println(interaction.outputText().orElse("")); if (interaction.outputImage().isPresent() && interaction.outputImage().get().data().isPresent()) { byte[] imageBytes = Base64.getDecoder().decode(interaction.outputImage().get().data().get()); Files.write(Paths.get("futuristic_city.png"), imageBytes); } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("A futuristic city built inside a giant glass bottle floating in space"), GenerationConfig: &interactions.GenerationConfig{ ThinkingLevel: interactions.ThinkingLevelHigh.ToPointer(), }, }), }) if err != nil { log.Fatal(err) } if res.Interaction.OutputText != nil { fmt.Println(*res.Interaction.OutputText) } if res.Interaction.OutputImage != nil && res.Interaction.OutputImage.Data != nil { imageBytes, err := base64.StdEncoding.DecodeString(*res.Interaction.OutputImage.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("futuristic_city.png", imageBytes, 0644); err != nil { log.Fatal(err) } } } ``` {% /tab %} {% tab label="REST" %} ```shell curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -H "Api-Revision: 2026-05-20" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "A futuristic city built inside a giant glass bottle floating in space", "generation_config": { "thinking_level": "high" } }' ``` {% /tab %} {% /tabs %} Note that thinking tokens are billed by default for thinking models, as the [thinking process](/docs/image-generation#thinking-process) always happens by default whether you view the process or not. ## Other image generation modes {% id="other-modes" %} Although Nano Banana image generation models are recommended for most use cases, you can also explore dedicated image generation models: * **Imagen**: Google's legacy text-to-image models (shut down). * **[Veo](/docs/video)**: Google's video generation model. ## Generate images in batch {% id="batch-api" %} All of the image generation capabilities described on this page can also be run as batch jobs using the [Batch API](/docs/batch-api). ## Prompting guide and strategies {% id="prompt-guide" %} This section provides prompt examples and templates for common image generation and editing workflows. Each example includes a re-usable template and a sample prompt for the Interactions API. ### Prompts for generating images {% id="image-generation-prompts" %} The following examples show how to use text prompts to generate various types of images. #### 1. Photorealistic scenes {% id="1-photorealistic-scenes" %} Describe a scene in rich detail. The more specific you are, the more control you have over the results. {% tabs %} {% tab label="Template" %} ```none A photorealistic [type of shot] of a [subject description] in a [setting description]. [Description of the light]. Shot from a [camera angle] with a [lens type]. ``` {% /tab %} {% tab label="Prompt" %} ```none A photorealistic wide-angle shot of a vibrant coral reef teeming with tropical fish. Crystal-clear turquoise water with sunbeams filtering down from the surface, illuminating a sea turtle gliding gracefully over the coral. Shot from a low perspective with a wide-angle lens. Aspect ratio 16:9. ``` {% /tab %} {% tab label="Python" %} ```python from google import genai from google.genai import types import base64 client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input="A photorealistic wide-angle shot of a vibrant coral reef teeming with tropical fish. Crystal-clear turquoise water with sunbeams filtering down from the surface, illuminating a sea turtle gliding gracefully over the coral. Shot from a low perspective with a wide-angle lens. Aspect ratio 16:9.", response_format=[ { "type": "image", "mime_type": "image/jpeg", "aspect_ratio": "16:9", } ], ) print(interaction.output_text) with open("coral_reef.png", "wb") as f: f.write(base64.b64decode(interaction.output_image.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "A photorealistic wide-angle shot of a vibrant coral reef teeming with tropical fish. Crystal-clear turquoise water with sunbeams filtering down from the surface, illuminating a sea turtle gliding gracefully over the coral. Shot from a low perspective with a wide-angle lens. Aspect ratio 16:9.", response_format: [ { type: "image", mime_type: "image/jpeg", aspect_ratio: "16:9", } ], }); console.log(interaction.output_text); if (interaction.output_image && interaction.output_image.data) { const buffer = Buffer.from(interaction.output_image.data, 'base64'); fs.writeFileSync('coral_reef.png', buffer); } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormatAspectRatio; import com.google.genai.gaos.models.interactions.ImageResponseFormatMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ResponseFormat; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; Client client = new Client(); CreateModelInteractionResponseFormat format = CreateModelInteractionResponseFormat.of( Arrays.asList( ResponseFormat.of( ImageResponseFormat.builder() .mimeType(ImageResponseFormatMimeType.IMAGE_JPEG) .aspectRatio(ImageResponseFormatAspectRatio.of("16:9")) .build()))); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "A photorealistic wide-angle shot of a vibrant coral reef teeming with tropical fish. Crystal-clear turquoise water with sunbeams filtering down from the surface, illuminating a sea turtle gliding gracefully over the coral. Shot from a low perspective with a wide-angle lens. Aspect ratio 16:9.")) .responseFormat(format) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); System.out.println(interaction.outputText().orElse("")); if (interaction.outputImage().isPresent() && interaction.outputImage().get().data().isPresent()) { byte[] imageBytes = Base64.getDecoder().decode(interaction.outputImage().get().data().get()); Files.write(Paths.get("coral_reef.png"), imageBytes); } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } format := interactions.NewCreateModelInteractionResponseFormat([]interactions.ResponseFormat{ interactions.NewResponseFormat(interactions.ImageResponseFormat{ MimeType: interactions.ImageResponseFormatMimeTypeImageJpeg.ToPointer(), AspectRatio: interactions.ImageResponseFormatAspectRatio("16:9").ToPointer(), }), }) res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("A photorealistic wide-angle shot of a vibrant coral reef teeming with tropical fish. Crystal-clear turquoise water with sunbeams filtering down from the surface, illuminating a sea turtle gliding gracefully over the coral. Shot from a low perspective with a wide-angle lens. Aspect ratio 16:9."), ResponseFormat: genai.Ptr(format), }), }) if err != nil { log.Fatal(err) } if res.Interaction.OutputText != nil { fmt.Println(*res.Interaction.OutputText) } if res.Interaction.OutputImage != nil && res.Interaction.OutputImage.Data != nil { imageBytes, err := base64.StdEncoding.DecodeString(*res.Interaction.OutputImage.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("coral_reef.png", imageBytes, 0644); err != nil { log.Fatal(err) } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -H "Api-Revision: 2026-05-20" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "A photorealistic wide-angle shot of a vibrant coral reef teeming with tropical fish. Crystal-clear turquoise water with sunbeams filtering down from the surface, illuminating a sea turtle gliding gracefully over the coral. Shot from a low perspective with a wide-angle lens. Aspect ratio 16:9.", "response_format": { "type": "image", "mime_type": "image/png", "aspect_ratio": "16:9" } }' ``` {% /tab %} {% /tabs %} #### 2. Stylized illustrations & stickers {% id="2-stylized-illustrations-stickers" %} Describe the artistic style, subject, and medium. Be specific about the visual detail (bold lines, colors, etc.) for consistent results. {% tabs %} {% tab label="Template" %} ```none A [style] of a [subject, with details about accessories or actions] doing [activity]. The design features [visual qualities, e.g., bold outlines, cel-shading, etc.] and [color/background preference]. ``` {% /tab %} {% tab label="Prompt" %} ```none A kawaii-style sticker of a happy red panda wearing a tiny bamboo hat. It's munching on a green bamboo leaf. The design features bold, clean outlines, simple cel-shading, and a vibrant color palette. The background must be white. ``` {% /tab %} {% tab label="Python" %} ```python from google import genai import base64 client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input="A kawaii-style sticker of a happy red panda wearing a tiny bamboo hat. It's munching on a green bamboo leaf. The design features bold, clean outlines, simple cel-shading, and a vibrant color palette. The background must be white.", ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("red_panda_sticker.png", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "A kawaii-style sticker of a happy red panda wearing a tiny bamboo hat. It's munching on a green bamboo leaf. The design features bold, clean outlines, simple cel-shading, and a vibrant color palette. The background must be white.", }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("red_panda_sticker.png", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Base64; Client client = new Client(); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "A kawaii-style sticker of a happy red panda wearing a tiny bamboo hat. It's munching on a green bamboo leaf. The design features bold, clean outlines, simple cel-shading, and a vibrant color palette. The background must be white.")) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] imgBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("red_panda_sticker.png"), imgBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("A kawaii-style sticker of a happy red panda wearing a tiny bamboo hat. It's munching on a green bamboo leaf. The design features bold, clean outlines, simple cel-shading, and a vibrant color palette. The background must be white."), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { imgBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("red_panda_sticker.png", imgBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "A kawaii-style sticker of a happy red panda wearing a tiny bamboo hat. It is munching on a green bamboo leaf. The design features bold, clean outlines, simple cel-shading, and a vibrant color palette. The background must be white." }' ``` {% /tab %} {% /tabs %} ![](https://www.gstatic.com/cloud-cms/239971d11d553532aaf0f70ca49f30ef.png)#### 3. Accurate text in images {% id="3-accurate-text-in-images" %} Gemini excels at rendering text. Be clear about the text, the font style (descriptively), and the overall design. Use Gemini 3 Pro Image for professional asset production. {% tabs %} {% tab label="Template" %} ```none Create a [image type] for [brand/concept] with the text "[text to render]" in a [font style]. The design should be [style description], with a [color scheme]. ``` {% /tab %} {% tab label="Prompt" %} ```none Create a modern, minimalist logo for a coffee shop called 'The Daily Grind'. The text should be in a clean, bold, sans-serif font. The color scheme is black and white. Put the logo in a circle. Use a coffee bean in a clever way. ``` {% /tab %} {% tab label="Python" %} ```python from google import genai import base64 client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input="Create a modern, minimalist logo for a coffee shop called 'The Daily Grind'. The text should be in a clean, bold, sans-serif font. The color scheme is black and white. Put the logo in a circle. Use a coffee bean in a clever way.", response_format={"type": "image", "aspect_ratio": "1:1"}, ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("logo_example.jpg", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "Create a modern, minimalist logo for a coffee shop called 'The Daily Grind'. The text should be in a clean, bold, sans-serif font. The color scheme is black and white. Put the logo in a circle. Use a coffee bean in a clever way.", response_format: { type: "image", aspect_ratio: "1:1" }, }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("logo_example.jpg", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormatAspectRatio; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.ResponseFormat; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Base64; Client client = new Client(); CreateModelInteractionResponseFormat format = CreateModelInteractionResponseFormat.of( ResponseFormat.of( ImageResponseFormat.builder() .aspectRatio(ImageResponseFormatAspectRatio.of("1:1")) .build())); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "Create a modern, minimalist logo for a coffee shop called 'The Daily Grind'. The text should be in a clean, bold, sans-serif font. The color scheme is black and white. Put the logo in a circle. Use a coffee bean in a clever way.")) .responseFormat(format) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] imgBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("logo_example.jpg"), imgBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } format := interactions.NewCreateModelInteractionResponseFormat( interactions.NewResponseFormat(interactions.ImageResponseFormat{ AspectRatio: interactions.ImageResponseFormatAspectRatio("1:1").ToPointer(), }), ) res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("Create a modern, minimalist logo for a coffee shop called 'The Daily Grind'. The text should be in a clean, bold, sans-serif font. The color scheme is black and white. Put the logo in a circle. Use a coffee bean in a clever way."), ResponseFormat: genai.Ptr(format), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { imgBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("logo_example.jpg", imgBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "Create a modern, minimalist logo for a coffee shop called The Daily Grind. The text should be in a clean, bold, sans-serif font. The color scheme is black and white. Put the logo in a circle. Use a coffee bean in a clever way.", "response_format": { "type": "image", "aspect_ratio": "1:1" } }' ``` {% /tab %} {% /tabs %} ![](https://www.gstatic.com/cloud-cms/f501e05c7e3dbb96395eb156fa3faeb4.jpg)#### 4. Product mockups & commercial photography {% id="4-product-mockups-commercial-photography" %} Perfect for creating clean, professional product shots for ecommerce, advertising, or branding. {% tabs %} {% tab label="Template" %} ```none A high-resolution, studio-lit product photograph of a [product description] on a [background surface/description]. The lighting is a [lighting setup, e.g., three-point softbox setup] to [lighting purpose]. The camera angle is a [angle type] to showcase [specific feature]. Ultra-realistic, with sharp focus on [key detail]. [Aspect ratio]. ``` {% /tab %} {% tab label="Prompt" %} ```none A high-resolution, studio-lit product photograph of a minimalist ceramic coffee mug in matte black, presented on a polished concrete surface. The lighting is a three-point softbox setup designed to create soft, diffused highlights and eliminate harsh shadows. The camera angle is a slightly elevated 45-degree shot to showcase its clean lines. Ultra-realistic, with sharp focus on the steam rising from the coffee. Square image. ``` {% /tab %} {% tab label="Python" %} ```python from google import genai import base64 client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input="A high-resolution, studio-lit product photograph of a minimalist ceramic coffee mug in matte black, presented on a polished concrete surface. The lighting is a three-point softbox setup designed to create soft, diffused highlights and eliminate harsh shadows. The camera angle is a slightly elevated 45-degree shot to showcase its clean lines. Ultra-realistic, with sharp focus on the steam rising from the coffee. Square image.", ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("product_mockup.png", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "A high-resolution, studio-lit product photograph of a minimalist ceramic coffee mug in matte black, presented on a polished concrete surface. The lighting is a three-point softbox setup designed to create soft, diffused highlights and eliminate harsh shadows. The camera angle is a slightly elevated 45-degree shot to showcase its clean lines. Ultra-realistic, with sharp focus on the steam rising from the coffee. Square image.", }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("product_mockup.png", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Base64; Client client = new Client(); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "A high-resolution, studio-lit product photograph of a minimalist ceramic coffee mug in matte black, presented on a polished concrete surface. The lighting is a three-point softbox setup designed to create soft, diffused highlights and eliminate harsh shadows. The camera angle is a slightly elevated 45-degree shot to showcase its clean lines. Ultra-realistic, with sharp focus on the steam rising from the coffee. Square image.")) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] imgBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("product_mockup.png"), imgBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("A high-resolution, studio-lit product photograph of a minimalist ceramic coffee mug in matte black, presented on a polished concrete surface. The lighting is a three-point softbox setup designed to create soft, diffused highlights and eliminate harsh shadows. The camera angle is a slightly elevated 45-degree shot to showcase its clean lines. Ultra-realistic, with sharp focus on the steam rising from the coffee. Square image."), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { imgBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("product_mockup.png", imgBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "A high-resolution, studio-lit product photograph of a minimalist ceramic coffee mug in matte black, presented on a polished concrete surface. The lighting is a three-point softbox setup designed to create soft, diffused highlights and eliminate harsh shadows. The camera angle is a slightly elevated 45-degree shot to showcase its clean lines. Ultra-realistic, with sharp focus on the steam rising from the coffee. Square image." }' ``` {% /tab %} {% /tabs %} ![](https://www.gstatic.com/cloud-cms/4c77e8a2b3655d5d94b134b073b976c2.png)#### 5. Minimalist & negative space design {% id="5-minimalist-negative-space-design" %} Excellent for creating backgrounds for websites, presentations, or marketing materials where text will be overlaid. {% tabs %} {% tab label="Template" %} ```none A minimalist composition featuring a single [subject] positioned in the [bottom-right/top-left/etc.] of the frame. The background is a vast, empty [color] canvas, creating significant negative space. Soft, subtle lighting. [Aspect ratio]. ``` {% /tab %} {% tab label="Prompt" %} ```none A minimalist composition featuring a single, delicate red maple leaf positioned in the bottom-right of the frame. The background is a vast, empty off-white canvas, creating significant negative space for text. Soft, diffused lighting from the top left. Square image. ``` {% /tab %} {% tab label="Python" %} ```python from google import genai import base64 client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input="A minimalist composition featuring a single, delicate red maple leaf positioned in the bottom-right of the frame. The background is a vast, empty off-white canvas, creating significant negative space for text. Soft, diffused lighting from the top left. Square image.", ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("minimalist_design.png", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "A minimalist composition featuring a single, delicate red maple leaf positioned in the bottom-right of the frame. The background is a vast, empty off-white canvas, creating significant negative space for text. Soft, diffused lighting from the top left. Square image.", }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("minimalist_design.png", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Base64; Client client = new Client(); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "A minimalist composition featuring a single, delicate red maple leaf positioned in the bottom-right of the frame. The background is a vast, empty off-white canvas, creating significant negative space for text. Soft, diffused lighting from the top left. Square image.")) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] imgBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("minimalist_design.png"), imgBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("A minimalist composition featuring a single, delicate red maple leaf positioned in the bottom-right of the frame. The background is a vast, empty off-white canvas, creating significant negative space for text. Soft, diffused lighting from the top left. Square image."), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { imgBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("minimalist_design.png", imgBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "A minimalist composition featuring a single, delicate red maple leaf positioned in the bottom-right of the frame. The background is a vast, empty off-white canvas, creating significant negative space for text. Soft, diffused lighting from the top left. Square image." }' ``` {% /tab %} {% /tabs %} ![](https://www.gstatic.com/cloud-cms/eabdf57912bb9e3412cb7ae92f1e7ce6.png)#### 6. Sequential art (Comic panel / Storyboard) {% id="6-sequential-art-comic-panel-storyboard" %} Builds on character consistency and scene description to create panels for visual storytelling. For accuracy with text and storytelling ability, these prompts work best with Gemini 3 Pro and Gemini 3.1 Flash Image. {% tabs %} {% tab label="Template" %} ```none Make a 3 panel comic in a [style]. Put the character in a [type of scene]. ``` {% /tab %} {% tab label="Prompt" %} ```none Make a 3 panel comic in a gritty, noir art style with high-contrast black and white inks. Put the character in a humurous scene. ``` {% /tab %} {% tab label="Python" %} ```python from google import genai from PIL import Image import base64 client = genai.Client() with open('/path/to/your/man_in_white_glasses.jpg', 'rb') as f: image_bytes = f.read() text_input = "Make a 3 panel comic in a gritty, noir art style with high-contrast black and white inks. Put the character in a humurous scene." interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=[ {"type": "text", "text": text_input}, { "type": "image", "data": base64.b64encode(image_bytes).decode('utf-8'), "mime_type": "image/jpeg" } ], ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("comic_panel.jpg", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const imagePath = "/path/to/your/man_in_white_glasses.jpg"; const imageData = fs.readFileSync(imagePath); const base64Image = imageData.toString("base64"); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: [ { type: "text", text: "Make a 3 panel comic in a gritty, noir art style with high-contrast black and white inks. Put the character in a humurous scene." }, { type: "image", mime_type: "image/jpeg", data: base64Image }, ], }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("comic_panel.jpg", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageContentMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; import java.util.List; Client client = new Client(); byte[] imageBytes = Files.readAllBytes(Paths.get("/path/to/your/man_in_white_glasses.jpg")); String base64Image = Base64.getEncoder().encodeToString(imageBytes); String textInput = "Make a 3 panel comic in a gritty, noir art style with high-contrast black and white inks. Put the character in a humurous scene."; Content textContent = TextContent.builder().text(textInput).build(); Content imageContent = ImageContent.builder() .data(base64Image) .mimeType(ImageContentMimeType.IMAGE_JPEG) .build(); List contents = Arrays.asList(textContent, imageContent); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.ofContent(contents)) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] outBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("comic_panel.jpg"), outBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } imageBytes, err := os.ReadFile("/path/to/your/man_in_white_glasses.jpg") if err != nil { log.Fatal(err) } base64Image := base64.StdEncoding.EncodeToString(imageBytes) textInput := "Make a 3 panel comic in a gritty, noir art style with high-contrast black and white inks. Put the character in a humurous scene." contents := []interactions.Content{ interactions.NewContent(interactions.TextContent{ Text: textInput, }), interactions.NewContent(interactions.ImageContent{ Data: genai.Ptr(base64Image), MimeType: interactions.ImageContentMimeTypeImageJpeg.ToPointer(), }), } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(contents), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { outBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("comic_panel.jpg", outBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-nano-banana-2.1", "input": [ {"type": "text", "text": "Make a 3 panel comic in a gritty, noir art style with high-contrast black and white inks. Put the character in a humurous scene."}, {"type": "image", "data": "[BASE64_IMAGE_DATA]", "mime_type": "image/jpeg"} ] }' ``` {% /tab %} {% /tabs %} {% table %} * Input * Output --- * ![](https://www.gstatic.com/cloud-cms/75f6d00e713587601b3fde0d1ce3f39f.jpg) Input image * ![](https://www.gstatic.com/cloud-cms/aa62e80cd0c43fa1a4f086d3e4c720fb.jpg) Make a 3 panel comic in a gritty, noir art style... {% /table %} #### 7. Grounding with Google Search {% id="grounding-with-search" %} Use Google Search to generate images based on recent or real-time information. This is useful for news, weather, and other time-sensitive topics. {% tabs %} {% tab label="Prompt" %} ```none Make a simple but stylish graphic of last night's Arsenal game in the Champion's League ``` {% /tab %} {% tab label="Python" %} ```python from google import genai from google.genai import types import base64 client = genai.Client() interaction = client.interactions.create( model="gemini-nano-banana-2.1", input="Make a simple but stylish graphic of last night's Arsenal game in the Champion's League", tools=[{"type": "google_search"}], response_format={"type": "image", "aspect_ratio": "16:9"}, ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("football-score.jpg", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "Make a simple but stylish graphic of last night's Arsenal game in the Champion's League", tools: [{ type: "google_search" }], response_format: { type: "image", aspect_ratio: "16:9", image_size: "2K" }, }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("football-score.jpg", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat; import com.google.genai.gaos.models.interactions.GoogleSearch; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormatAspectRatio; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.ResponseFormat; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; Client client = new Client(); CreateModelInteractionResponseFormat format = CreateModelInteractionResponseFormat.of( ResponseFormat.of( ImageResponseFormat.builder() .aspectRatio(ImageResponseFormatAspectRatio.of("16:9")) .build())); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "Make a simple but stylish graphic of last night's Arsenal game in the Champion's League")) .tools(Arrays.asList(new GoogleSearch())) .responseFormat(format) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] imgBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("football-score.jpg"), imgBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } format := interactions.NewCreateModelInteractionResponseFormat( interactions.NewResponseFormat(interactions.ImageResponseFormat{ AspectRatio: interactions.ImageResponseFormatAspectRatio("16:9").ToPointer(), }), ) res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("Make a simple but stylish graphic of last night's Arsenal game in the Champion's League"), Tools: []interactions.Tool{ interactions.NewTool(interactions.GoogleSearch{}), }, ResponseFormat: genai.Ptr(format), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { imgBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("football-score.jpg", imgBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "Make a simple but stylish graphic of last nights Arsenal game in the Champions League", "tools": [{"type": "google_search"}], "response_format": { "type": "image", "aspect_ratio": "16:9" } }' ``` {% /tab %} {% /tabs %} ![](https://www.gstatic.com/cloud-cms/ab8ab85b1d93b1802adeb3ea7c3b8bea.jpg)### Prompts for editing images {% id="image-editing-prompts" %} These examples show how to provide images alongside your text prompts for editing, composition, and style transfer. #### 1. Adding and removing elements {% id="1-adding-and-removing-elements" %} Provide an image and describe your change. The model will match the original image's style, lighting, and perspective. {% tabs %} {% tab label="Template" %} ```none Using the provided image of [subject], please [add/remove/modify] [element] to/from the scene. Ensure the change is [description of how the change should integrate]. ``` {% /tab %} {% tab label="Prompt" %} ```none "Using the provided image of my cat, please add a small, knitted wizard hat on its head. Make it look like it's sitting comfortably and matches the soft lighting of the photo." ``` {% /tab %} {% tab label="Python" %} ```python from google import genai from PIL import Image import base64 client = genai.Client() with open('/path/to/your/cat_photo.png', 'rb') as f: image_bytes = f.read() text_input = """Using the provided image of my cat, please add a small, knitted wizard hat on its head. Make it look like it's sitting comfortably and not falling off.""" interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=[ {"type": "text", "text": text_input}, { "type": "image", "data": base64.b64encode(image_bytes).decode('utf-8'), "mime_type": "image/png" } ], ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("cat_with_hat.png", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const imagePath = "/path/to/your/cat_photo.png"; const imageData = fs.readFileSync(imagePath); const base64Image = imageData.toString("base64"); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: [ { type: "text", text: "Using the provided image of my cat, please add a small, knitted wizard hat on its head. Make it look like it's sitting comfortably and not falling off." }, { type: "image", mime_type: "image/png", data: base64Image }, ], }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("cat_with_hat.png", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageContentMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; import java.util.List; Client client = new Client(); byte[] imageBytes = Files.readAllBytes(Paths.get("/path/to/your/cat_photo.png")); String base64Image = Base64.getEncoder().encodeToString(imageBytes); String textInput = "Using the provided image of my cat, please add a small, knitted wizard hat on its head. Make it look like it's sitting comfortably and not falling off."; Content textContent = TextContent.builder().text(textInput).build(); Content imageContent = ImageContent.builder() .data(base64Image) .mimeType(ImageContentMimeType.IMAGE_PNG) .build(); List contents = Arrays.asList(textContent, imageContent); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.ofContent(contents)) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] outBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("cat_with_hat.png"), outBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } imageBytes, err := os.ReadFile("/path/to/your/cat_photo.png") if err != nil { log.Fatal(err) } base64Image := base64.StdEncoding.EncodeToString(imageBytes) textInput := "Using the provided image of my cat, please add a small, knitted wizard hat on its head. Make it look like it's sitting comfortably and not falling off." contents := []interactions.Content{ interactions.NewContent(interactions.TextContent{ Text: textInput, }), interactions.NewContent(interactions.ImageContent{ Data: genai.Ptr(base64Image), MimeType: interactions.ImageContentMimeTypeImagePng.ToPointer(), }), } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(contents), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { outBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("cat_with_hat.png", outBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -d "{ \"model\": \"gemini-nano-banana-2.1\", \"input\": [ {\"type\": \"text\", \"text\": \"Using the provided image of my cat, please add a small, knitted wizard hat on its head. Make it look like it's sitting comfortably and not falling off.\"}, {\"type\": \"image\", \"mime_type\":\"image/png\", \"data\": \"[BASE64_IMAGE_DATA]\"} ] }" ``` {% /tab %} {% /tabs %} {% table %} * Input * Output --- * ![](https://www.gstatic.com/cloud-cms/4a26c9e6a813d316fcc515db9c6721e8.png) A photorealistic picture of a fluffy ginger cat... * ![](https://www.gstatic.com/cloud-cms/aaf4ca309bb3731c7a607e89dddd8a7a.png) Using the provided image of my cat, please add a small, knitted wizard hat... {% /table %} #### 2. Inpainting (Semantic masking) {% id="2-inpainting-semantic-masking" %} Conversationally define a "mask" to edit a specific part of an image while leaving the rest untouched. {% tabs %} {% tab label="Template" %} ```none Using the provided image, change only the [specific element] to [new element/description]. Keep everything else in the image exactly the same, preserving the original style, lighting, and composition. ``` {% /tab %} {% tab label="Prompt" %} ```none "Using the provided image of a living room, change only the blue sofa to be a vintage, brown leather chesterfield sofa. Keep the rest of the room, including the pillows on the sofa and the lighting, unchanged." ``` {% /tab %} {% tab label="Python" %} ```python from google import genai from PIL import Image import base64 client = genai.Client() with open('/path/to/your/living_room.png', 'rb') as f: image_bytes = f.read() text_input = """Using the provided image of a living room, change only the blue sofa to be a vintage, brown leather chesterfield sofa. Keep the rest of the room, including the pillows on the sofa and the lighting, unchanged.""" interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=[ { "type": "image", "data": base64.b64encode(image_bytes).decode('utf-8'), "mime_type": "image/png" }, {"type": "text", "text": text_input} ], ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("living_room_edited.png", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const imagePath = "/path/to/your/living_room.png"; const imageData = fs.readFileSync(imagePath); const base64Image = imageData.toString("base64"); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: [ { type: "image", mime_type: "image/png", data: base64Image }, { type: "text", text: "Using the provided image of a living room, change only the blue sofa to be a vintage, brown leather chesterfield sofa. Keep the rest of the room, including the pillows on the sofa and the lighting, unchanged." }, ], }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("living_room_edited.png", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageContentMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; import java.util.List; Client client = new Client(); byte[] imageBytes = Files.readAllBytes(Paths.get("/path/to/your/living_room.png")); String base64Image = Base64.getEncoder().encodeToString(imageBytes); String textInput = "Using the provided image of a living room, change only the blue sofa to be a vintage, brown leather chesterfield sofa. Keep the rest of the room, including the pillows on the sofa and the lighting, unchanged."; Content imageContent = ImageContent.builder() .data(base64Image) .mimeType(ImageContentMimeType.IMAGE_PNG) .build(); Content textContent = TextContent.builder().text(textInput).build(); List contents = Arrays.asList(imageContent, textContent); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.ofContent(contents)) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] outBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("living_room_edited.png"), outBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } imageBytes, err := os.ReadFile("/path/to/your/living_room.png") if err != nil { log.Fatal(err) } base64Image := base64.StdEncoding.EncodeToString(imageBytes) textInput := "Using the provided image of a living room, change only the blue sofa to be a vintage, brown leather chesterfield sofa. Keep the rest of the room, including the pillows on the sofa and the lighting, unchanged." contents := []interactions.Content{ interactions.NewContent(interactions.ImageContent{ Data: genai.Ptr(base64Image), MimeType: interactions.ImageContentMimeTypeImagePng.ToPointer(), }), interactions.NewContent(interactions.TextContent{ Text: textInput, }), } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(contents), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { outBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("living_room_edited.png", outBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -d "{ \"model\": \"gemini-nano-banana-2.1\", \"input\": [ {\"type\": \"image\", \"mime_type\":\"image/png\", \"data\": \"[BASE64_IMAGE_DATA]\"}, {\"type\": \"text\", \"text\": \"Using the provided image of a living room, change only the blue sofa to be a vintage, brown leather chesterfield sofa. Keep the rest of the room, including the pillows on the sofa and the lighting, unchanged.\"} ] }" ``` {% /tab %} {% /tabs %} {% table %} * Input * Output --- * ![](https://www.gstatic.com/cloud-cms/c4bc515821aabf9438b4140dd581ee04.png) A wide shot of a modern, well-lit living room... * ![](https://www.gstatic.com/cloud-cms/50e14b41157a17030d665ec71fbe17e0.png) Using the provided image of a living room, change only the blue sofa to be a vintage, brown leather chesterfield sofa... {% /table %} #### 3. Style transfer {% id="3-style-transfer" %} Provide an image and ask the model to recreate its content in a different artistic style. {% tabs %} {% tab label="Template" %} ```none Transform the provided photograph of [subject] into the artistic style of [artist/art style]. Preserve the original composition but render it with [description of stylistic elements]. ``` {% /tab %} {% tab label="Prompt" %} ```none "Transform the provided photograph of a modern city street at night into the artistic style of Vincent van Gogh's 'Starry Night'. Preserve the original composition of buildings and cars, but render all elements with swirling, impasto brushstrokes and a dramatic palette of deep blues and bright yellows." ``` {% /tab %} {% tab label="Python" %} ```python from google import genai from PIL import Image import base64 client = genai.Client() with open('/path/to/your/city.png', 'rb') as f: image_bytes = f.read() text_input = """Transform the provided photograph of a modern city street at night into the artistic style of Vincent van Gogh's 'Starry Night'. Preserve the original composition of buildings and cars, but render all elements with swirling, impasto brushstrokes and a dramatic palette of deep blues and bright yellows.""" interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=[ { "type": "image", "data": base64.b64encode(image_bytes).decode('utf-8'), "mime_type": "image/png" }, {"type": "text", "text": text_input} ], ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("city_style_transfer.png", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const imageData = fs.readFileSync("/path/to/your/city.png"); const base64Image = imageData.toString("base64"); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: [ { type: "image", mime_type: "image/png", data: base64Image }, { type: "text", text: "Transform the provided photograph of a modern city street at night into the artistic style of Vincent van Gogh's 'Starry Night'. Preserve the original composition of buildings and cars, but render all elements with swirling, impasto brushstrokes and a dramatic palette of deep blues and bright yellows." }, ], }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("city_style_transfer.png", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageContentMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; import java.util.List; Client client = new Client(); byte[] imageBytes = Files.readAllBytes(Paths.get("/path/to/your/city.png")); String base64Image = Base64.getEncoder().encodeToString(imageBytes); String textInput = "Transform the provided photograph of a modern city street at night into the artistic style of Vincent van Gogh's 'Starry Night'. Preserve the original composition of buildings and cars, but render all elements with swirling, impasto brushstrokes and a dramatic palette of deep blues and bright yellows."; Content imageContent = ImageContent.builder() .data(base64Image) .mimeType(ImageContentMimeType.IMAGE_PNG) .build(); Content textContent = TextContent.builder().text(textInput).build(); List contents = Arrays.asList(imageContent, textContent); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.ofContent(contents)) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] outBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("city_style_transfer.png"), outBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } imageBytes, err := os.ReadFile("/path/to/your/city.png") if err != nil { log.Fatal(err) } base64Image := base64.StdEncoding.EncodeToString(imageBytes) textInput := "Transform the provided photograph of a modern city street at night into the artistic style of Vincent van Gogh's 'Starry Night'. Preserve the original composition of buildings and cars, but render all elements with swirling, impasto brushstrokes and a dramatic palette of deep blues and bright yellows." contents := []interactions.Content{ interactions.NewContent(interactions.ImageContent{ Data: genai.Ptr(base64Image), MimeType: interactions.ImageContentMimeTypeImagePng.ToPointer(), }), interactions.NewContent(interactions.TextContent{ Text: textInput, }), } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(contents), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { outBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("city_style_transfer.png", outBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -d "{ \"model\": \"gemini-nano-banana-2.1\", \"input\": [ {\"type\": \"image\", \"mime_type\":\"image/png\", \"data\": \"[BASE64_IMAGE_DATA]\"}, {\"type\": \"text\", \"text\": \"Transform the provided photograph of a modern city street at night into the artistic style of Vincent van Gogh's 'Starry Night'. Preserve the original composition of buildings and cars, but render all elements with swirling, impasto brushstrokes and a dramatic palette of deep blues and bright yellows.\"} ] }" ``` {% /tab %} {% /tabs %} {% table %} * Input * Output --- * ![](https://www.gstatic.com/cloud-cms/c6c7a301a3e30f428a159cd359f37827.png) A photorealistic, high-resolution photograph of a busy city street... * ![](https://www.gstatic.com/cloud-cms/e749119638b1abc50d2620ed76a60706.png) Transform the provided photograph of a modern city street at night... {% /table %} #### 4. Advanced composition: Combining multiple images {% id="4-advanced-composition-combining-multiple-images" %} Provide multiple images as context to create a new, composite scene. This is perfect for product mockups or creative collages. {% tabs %} {% tab label="Template" %} ```none Create a new image by combining the elements from the provided images. Take the [element from image 1] and place it with/on the [element from image 2]. The final image should be a [description of the final scene]. ``` {% /tab %} {% tab label="Prompt" %} ```none "Create a professional e-commerce fashion photo. Take the blue floral dress from the first image and let the woman from the second image wear it. Generate a realistic, full-body shot of the woman wearing the dress, with the lighting and shadows adjusted to match the outdoor environment." ``` {% /tab %} {% tab label="Python" %} ```python from google import genai from PIL import Image import base64 client = genai.Client() with open('/path/to/your/dress.png', 'rb') as f: dress_bytes = f.read() with open('/path/to/your/model.png', 'rb') as f: model_bytes = f.read() text_input = """Create a professional e-commerce fashion photo. Take the blue floral dress from the first image and let the woman from the second image wear it. Generate a realistic, full-body shot of the woman wearing the dress, with the lighting and shadows adjusted to match the outdoor environment.""" interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=[ { "type": "image", "data": base64.b64encode(dress_bytes).decode('utf-8'), "mime_type": "image/png" }, { "type": "image", "data": base64.b64encode(model_bytes).decode('utf-8'), "mime_type": "image/png" }, {"type": "text", "text": text_input} ], ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("fashion_ecommerce_shot.png", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const imagePath1 = "/path/to/your/dress.png"; const imageData1 = fs.readFileSync(imagePath1); const base64Image1 = imageData1.toString("base64"); const imagePath2 = "/path/to/your/model.png"; const imageData2 = fs.readFileSync(imagePath2); const base64Image2 = imageData2.toString("base64"); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: [ { type: "image", mime_type: "image/png", data: base64Image1 }, { type: "image", mime_type: "image/png", data: base64Image2 }, { type: "text", text: "Create a professional e-commerce fashion photo. Take the blue floral dress from the first image and let the woman from the second image wear it. Generate a realistic, full-body shot of the woman wearing the dress, with the lighting and shadows adjusted to match the outdoor environment." }, ], }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("fashion_ecommerce_shot.png", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageContentMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; import java.util.List; Client client = new Client(); byte[] dressBytes = Files.readAllBytes(Paths.get("/path/to/your/dress.png")); byte[] modelBytes = Files.readAllBytes(Paths.get("/path/to/your/model.png")); String textInput = "Create a professional e-commerce fashion photo. Take the blue floral dress from the first image and let the woman from the second image wear it. Generate a realistic, full-body shot of the woman wearing the dress, with the lighting and shadows adjusted to match the outdoor environment."; Content dressContent = ImageContent.builder() .data(Base64.getEncoder().encodeToString(dressBytes)) .mimeType(ImageContentMimeType.IMAGE_PNG) .build(); Content modelContent = ImageContent.builder() .data(Base64.getEncoder().encodeToString(modelBytes)) .mimeType(ImageContentMimeType.IMAGE_PNG) .build(); Content textContent = TextContent.builder().text(textInput).build(); List contents = Arrays.asList(dressContent, modelContent, textContent); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.ofContent(contents)) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] outBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("fashion_ecommerce_shot.png"), outBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } dressBytes, err := os.ReadFile("/path/to/your/dress.png") if err != nil { log.Fatal(err) } modelBytes, err := os.ReadFile("/path/to/your/model.png") if err != nil { log.Fatal(err) } textInput := "Create a professional e-commerce fashion photo. Take the blue floral dress from the first image and let the woman from the second image wear it. Generate a realistic, full-body shot of the woman wearing the dress, with the lighting and shadows adjusted to match the outdoor environment." contents := []interactions.Content{ interactions.NewContent(interactions.ImageContent{ Data: genai.Ptr(base64.StdEncoding.EncodeToString(dressBytes)), MimeType: interactions.ImageContentMimeTypeImagePng.ToPointer(), }), interactions.NewContent(interactions.ImageContent{ Data: genai.Ptr(base64.StdEncoding.EncodeToString(modelBytes)), MimeType: interactions.ImageContentMimeTypeImagePng.ToPointer(), }), interactions.NewContent(interactions.TextContent{ Text: textInput, }), } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(contents), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { outBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("fashion_ecommerce_shot.png", outBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -d "{ \"model\": \"gemini-nano-banana-2.1\", \"input\": [ {\"type\": \"image\", \"mime_type\":\"image/png\", \"data\": \"[BASE64_IMAGE_DATA_1]\"}, {\"type\": \"image\", \"mime_type\":\"image/png\", \"data\": \"[BASE64_IMAGE_DATA_2]\"}, {\"type\": \"text\", \"text\": \"Create a professional e-commerce fashion photo. Take the blue floral dress from the first image and let the woman from the second image wear it. Generate a realistic, full-body shot of the woman wearing the dress, with the lighting and shadows adjusted to match the outdoor environment.\"} }] }" ``` {% /tab %} {% /tabs %} {% table %} * Input 1 * Input 2 * Output --- * ![](https://www.gstatic.com/cloud-cms/ef38320013ceae07bd42686c364a16a3.png) A blue floral summer dress on a neutral background * ![](https://www.gstatic.com/cloud-cms/39a9891907e0a1b80ecb168c32bda34d.png) Full-body shot of a woman with her hair in a bun... * ![](https://www.gstatic.com/cloud-cms/e6ea1787bd4158e76d6490d18301d7fd.png) A woman wearing a blue floral summer dress in an outdoor setting {% /table %} #### 5. High-fidelity detail preservation {% id="5-high-fidelity-detail-preservation" %} To ensure critical details (like a face or logo) are preserved during an edit, describe them in great detail along with your edit request. {% tabs %} {% tab label="Template" %} ```none Using the provided images, place [element from image 2] onto [element from image 1]. Ensure that the features of [element from image 1] remain completely unchanged. The added element should [description of how the element should integrate]. ``` {% /tab %} {% tab label="Prompt" %} ```none "Take the first image of the woman with brown hair, blue eyes, and a neutral expression. Add the logo from the second image onto her black t-shirt. Ensure the woman's face and features remain completely unchanged. The logo should look like it's naturally printed on the fabric, following the folds of the shirt." ``` {% /tab %} {% tab label="Python" %} ```python from google import genai from PIL import Image import base64 client = genai.Client() with open('/path/to/your/woman.png', 'rb') as f: woman_bytes = f.read() with open('/path/to/your/logo.png', 'rb') as f: logo_bytes = f.read() text_input = """Take the first image of the woman with brown hair, blue eyes, and a neutral expression. Add the logo from the second image onto her black t-shirt. Ensure the woman's face and features remain completely unchanged. The logo should look like it's naturally printed on the fabric, following the folds of the shirt.""" interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=[ {"type": "image", "mime_type":"image/png", "data": base64.b64encode(woman_bytes).decode('utf-8')}, {"type": "image", "mime_type":"image/png", "data": base64.b64encode(logo_bytes).decode('utf-8')}, {"type": "text", "text": text_input} ], ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("woman_with_logo.png", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const imagePath1 = "/path/to/your/woman.png"; const imageData1 = fs.readFileSync(imagePath1); const base64Image1 = imageData1.toString("base64"); const imagePath2 = "/path/to/your/logo.png"; const imageData2 = fs.readFileSync(imagePath2); const base64Image2 = imageData2.toString("base64"); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: [ {"type": "image", "mime_type":"image/png", "data": base64Image1}, {"type": "image", "mime_type":"image/png", "data": base64Image2}, {"type": "text", "text": "Take the first image of the woman with brown hair, blue eyes, and a neutral expression. Add the logo from the second image onto her black t-shirt. Ensure the woman's face and features remain completely unchanged. The logo should look like it's naturally printed on the fabric, following the folds of the shirt."}, ], }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("woman_with_logo.png", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageContentMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; import java.util.List; Client client = new Client(); byte[] womanBytes = Files.readAllBytes(Paths.get("/path/to/your/woman.png")); byte[] logoBytes = Files.readAllBytes(Paths.get("/path/to/your/logo.png")); String textInput = "Take the first image of the woman with brown hair, blue eyes, and a neutral expression. Add the logo from the second image onto her black t-shirt. Ensure the woman's face and features remain completely unchanged. The logo should look like it's naturally printed on the fabric, following the folds of the shirt."; Content womanContent = ImageContent.builder() .data(Base64.getEncoder().encodeToString(womanBytes)) .mimeType(ImageContentMimeType.IMAGE_PNG) .build(); Content logoContent = ImageContent.builder() .data(Base64.getEncoder().encodeToString(logoBytes)) .mimeType(ImageContentMimeType.IMAGE_PNG) .build(); Content textContent = TextContent.builder().text(textInput).build(); List contents = Arrays.asList(womanContent, logoContent, textContent); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.ofContent(contents)) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] outBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("woman_with_logo.png"), outBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } womanBytes, err := os.ReadFile("/path/to/your/woman.png") if err != nil { log.Fatal(err) } logoBytes, err := os.ReadFile("/path/to/your/logo.png") if err != nil { log.Fatal(err) } textInput := "Take the first image of the woman with brown hair, blue eyes, and a neutral expression. Add the logo from the second image onto her black t-shirt. Ensure the woman's face and features remain completely unchanged. The logo should look like it's naturally printed on the fabric, following the folds of the shirt." contents := []interactions.Content{ interactions.NewContent(interactions.ImageContent{ Data: genai.Ptr(base64.StdEncoding.EncodeToString(womanBytes)), MimeType: interactions.ImageContentMimeTypeImagePng.ToPointer(), }), interactions.NewContent(interactions.ImageContent{ Data: genai.Ptr(base64.StdEncoding.EncodeToString(logoBytes)), MimeType: interactions.ImageContentMimeTypeImagePng.ToPointer(), }), interactions.NewContent(interactions.TextContent{ Text: textInput, }), } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(contents), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { outBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("woman_with_logo.png", outBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -d "{ \"model\": \"gemini-nano-banana-2.1\", \"input\": [ {\"type\": \"image\", \"mime_type\":\"image/png\", \"data\": \"[BASE64_IMAGE_DATA_1]\"}, {\"type\": \"image\", \"mime_type\":\"image/png\", \"data\": \"[BASE64_IMAGE_DATA_2]\"}, {\"type\": \"text\", \"text\": \"Take the first image of the woman with brown hair, blue eyes, and a neutral expression. Add the logo from the second image onto her black t-shirt. Ensure the woman's face and features remain completely unchanged. The logo should look like it's naturally printed on the fabric, following the folds of the shirt.\"} ] }" ``` {% /tab %} {% /tabs %} {% table %} * Input 1 * Input 2 * Output --- * ![](https://www.gstatic.com/cloud-cms/f1f3d04375e487bc630f1af0e2b081fb.png) A professional headshot of a woman with brown hair and blue eyes... * ![](https://www.gstatic.com/cloud-cms/5c6702cf25e4707c890457d7b315f0b2.png) Modern brand identifier with letters G and A * ![](https://www.gstatic.com/cloud-cms/2b6b85696ca48b750cffa82a29cf56b3.png) Take the first image of the woman with brown hair, blue eyes, and a neutral expression... {% /table %} #### 6. Bring something to life {% id="6-bring-something-to-life" %} Upload a rough sketch or drawing and ask the model to refine it into a finished image. {% tabs %} {% tab label="Template" %} ```none Turn this rough [medium] sketch of a [subject] into a [style description] photo. Keep the [specific features] from the sketch but add [new details/materials]. ``` {% /tab %} {% tab label="Prompt" %} ```none "Turn this rough pencil sketch of a futuristic car into a polished photo of the finished concept car in a showroom. Keep the sleek lines and low profile from the sketch but add metallic blue paint and neon rim lighting." ``` {% /tab %} {% tab label="Python" %} ```python from google import genai from PIL import Image import base64 client = genai.Client() with open('/path/to/your/car_sketch.png', 'rb') as f: sketch_bytes = f.read() text_input = """Turn this rough pencil sketch of a futuristic car into a polished photo of the finished concept car in a showroom. Keep the sleek lines and low profile from the sketch but add metallic blue paint and neon rim lighting.""" interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=[ {"type": "image", "mime_type":"image/png", "data": base64.b64encode(sketch_bytes).decode('utf-8')}, {"type": "text", "text": text_input} ], ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("car_photo.png", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; import * as fs from "node:fs"; async function main() { const ai = new GoogleGenAI({}); const imagePath = "/path/to/your/car_sketch.png"; const imageData = fs.readFileSync(imagePath); const base64Image = imageData.toString("base64"); const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: [ {"type": "image", "mime_type":"image/png", "data": base64Image}, {"type": "text", "text": "Turn this rough pencil sketch of a futuristic car into a polished photo of the finished concept car in a showroom. Keep the sleek lines and low profile from the sketch but add metallic blue paint and neon rim lighting."}, ], }); for (const step of interaction.steps) { if (step.type === "model_output") { for (const contentBlock of step.content || []) { if (contentBlock.type === "text") { console.log(contentBlock.text); } else if (contentBlock.type === "image") { if (contentBlock.data) { const buffer = Buffer.from(contentBlock.data, "base64"); fs.writeFileSync("car_photo.png", buffer); } } } } } } await main(); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageContentMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; import java.util.List; Client client = new Client(); byte[] sketchBytes = Files.readAllBytes(Paths.get("/path/to/your/car_sketch.png")); String textInput = "Turn this rough pencil sketch of a futuristic car into a polished photo of the finished concept car in a showroom. Keep the sleek lines and low profile from the sketch but add metallic blue paint and neon rim lighting."; Content sketchContent = ImageContent.builder() .data(Base64.getEncoder().encodeToString(sketchBytes)) .mimeType(ImageContentMimeType.IMAGE_PNG) .build(); Content textContent = TextContent.builder().text(textInput).build(); List contents = Arrays.asList(sketchContent, textContent); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.ofContent(contents)) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] outBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("car_photo.png"), outBytes); } } } } } } } ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "encoding/base64" "fmt" "log" "os" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } sketchBytes, err := os.ReadFile("/path/to/your/car_sketch.png") if err != nil { log.Fatal(err) } textInput := "Turn this rough pencil sketch of a futuristic car into a polished photo of the finished concept car in a showroom. Keep the sleek lines and low profile from the sketch but add metallic blue paint and neon rim lighting." contents := []interactions.Content{ interactions.NewContent(interactions.ImageContent{ Data: genai.Ptr(base64.StdEncoding.EncodeToString(sketchBytes)), MimeType: interactions.ImageContentMimeTypeImagePng.ToPointer(), }), interactions.NewContent(interactions.TextContent{ Text: textInput, }), } res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(contents), }), }) if err != nil { log.Fatal(err) } for _, step := range res.Interaction.Steps { if step.ModelOutputStep != nil { for _, contentBlock := range step.ModelOutputStep.Content { if contentBlock.TextContent != nil { fmt.Println(contentBlock.TextContent.Text) } else if contentBlock.ImageContent != nil && contentBlock.ImageContent.Data != nil { outBytes, err := base64.StdEncoding.DecodeString(*contentBlock.ImageContent.Data) if err != nil { log.Fatal(err) } if err := os.WriteFile("car_photo.png", outBytes, 0644); err != nil { log.Fatal(err) } } } } } } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -d "{ \"model\": \"gemini-nano-banana-2.1\", \"input\": [ {\"type\": \"image\", \"mime_type\":\"image/png\", \"data\": \"[BASE64_IMAGE_DATA]\"}, {\"type\": \"text\", \"text\": \"Turn this rough pencil sketch of a futuristic car into a polished photo of the finished concept car in a showroom. Keep the sleek lines and low profile from the sketch but add metallic blue paint and neon rim lighting.\"} ] }" ``` {% /tab %} {% /tabs %} {% table %} * Input * Output --- * ![](https://www.gstatic.com/cloud-cms/937f4ad9bbc91213c1b069acf78da4eb.jpg) Rough sketch of a car * ![](https://www.gstatic.com/cloud-cms/93d2f7208f11510ad185f0572c7ca616.jpg) Polished photo of a car {% /table %} #### 7. Character consistency: 360 view {% id="7-character-consistency-360-view" %} You can generate 360-degree views of a character by iteratively prompting for different angles. For best results, include previously generated images in subsequent prompts to maintain consistency. For complex poses, include a reference image of the selected pose. {% tabs %} {% tab label="Template" %} ```none A studio portrait of [person] against [background], [looking forward/in profile looking right/etc.] ``` {% /tab %} {% tab label="Prompt" %} ```none A studio portrait of this man against white, in profile looking right ``` {% /tab %} {% tab label="Python" %} ```python from google import genai from PIL import Image import base64 client = genai.Client() with open('/path/to/your/man_in_white_glasses.jpg', 'rb') as f: image_bytes = f.read() text_input = """A studio portrait of this man against white, in profile looking right""" interaction = client.interactions.create( model="gemini-nano-banana-2.1", input={ {"type": "text", "text": text_input}, {"type": "image", "mime_type":"image/png", "data": base64.b64encode(image_bytes).decode('utf-8')} }, ) for step in interaction.steps: if step.type == "model_output": for content_block in step.content: if content_block.type == "text": print(content_block.text) elif content_block.type == "image": with open("man_right_profile.png", "wb") as f: f.write(base64.b64decode(content_block.data)) ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.Content; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.ImageContent; import com.google.genai.gaos.models.interactions.ImageContentMimeType; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ModelOutputStep; import com.google.genai.gaos.models.interactions.Step; import com.google.genai.gaos.models.interactions.TextContent; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Base64; import java.util.List; Client client = new Client(); byte[] imageBytes = Files.readAllBytes(Paths.get("/path/to/your/man_in_white_glasses.jpg")); String textInput = "A studio portrait of this man against white, in profile looking right"; Content textContent = TextContent.builder().text(textInput).build(); Content imageContent = ImageContent.builder() .data(Base64.getEncoder().encodeToString(imageBytes)) .mimeType(ImageContentMimeType.IMAGE_PNG) .build(); List contents = Arrays.asList(textContent, imageContent); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.ofContent(contents)) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); if (interaction.steps().isPresent()) { for (Step step : interaction.steps().get()) { if (step instanceof ModelOutputStep) { ModelOutputStep outputStep = (ModelOutputStep) step; if (outputStep.content().isPresent()) { for (Content contentBlock : outputStep.content().get()) { if (contentBlock instanceof TextContent) { System.out.println(((TextContent) contentBlock).text().orElse("")); } else if (contentBlock instanceof ImageContent) { ImageContent img = (ImageContent) contentBlock; if (img.data().isPresent()) { byte[] outBytes = Base64.getDecoder().decode(img.data().get()); Files.write(Paths.get("man_right_profile.png"), outBytes); } } } } } } } ``` {% /tab %} {% /tabs %} {% table %} * Input * Output 1 * Output 2 --- * ![](https://www.gstatic.com/cloud-cms/75f6d00e713587601b3fde0d1ce3f39f.jpg) Original image * ![](https://www.gstatic.com/cloud-cms/2143d148c8ca3169e2d42869ab4af6a6.jpg) Man in white glasses looking right * ![](https://www.gstatic.com/cloud-cms/91dd9874fa2cd0fe714418c9a4ba9f5c.jpg) Man in white glasses looking forward {% /table %} ### Best Practices {% id="best-practices" %} To elevate your results from good to great, incorporate these professional strategies into your workflow. * **Be Hyper-Specific:** The more detail you provide, the more control you have. Instead of "fantasy armor," describe it: "ornate elven plate armor, etched with silver leaf patterns, with a high collar and pauldrons shaped like falcon wings." * **Provide Context and Intent:** Explain the *purpose* of the image. The model's understanding of context will influence the final output. For example, "Create a logo for a high-end, minimalist skincare brand" will yield better results than just "Create a logo." * **Iterate and Refine:** Don't expect a perfect image on the first try. Use the conversational nature of the model to make small changes. Follow up with prompts like, "That's great, but can you make the lighting a bit warmer?" or "Keep everything the same, but change the character's expression to be more serious." * **Use Step-by-Step Instructions:** For complex scenes with many elements, break your prompt into steps. "First, create a background of a serene, misty forest at dawn. Then, in the foreground, add a moss-covered ancient stone altar. Finally, place a single, glowing sword on top of the altar." * **Use "Semantic Negative Prompts":** Instead of saying "no cars," describe the intended scene positively: "an empty, deserted street with no signs of traffic." * **Control the Camera:** Use photographic and cinematic language to control the composition. Terms like `wide-angle shot`, `macro shot`, `low-angle perspective`. ## Limitations {% id="limitations" %} * For best performance, use the following languages: EN, ar-EG, de-DE, es-MX, fr-FR, hi-IN, id-ID, it-IT, ja-JP, ko-KR, pt-BR, ru-RU, ua-UA, vi-VN, zh-CN. * Image generation does not support audio inputs. Video inputs are only supported for Gemini Nano Banana 2.1, Gemini 3.1 Flash Image, and Gemini 3.1 Flash Lite Image. * The model won't always follow the exact number of image outputs that the user explicitly asks for. * `gemini-2.5-flash-image` works best with up to 3 images as input, while `gemini-3-pro-image` supports 5 images with high fidelity, and up to 14 images in total. `gemini-nano-banana-2.1` and `gemini-3.1-flash-image` support character resemblance of up to 4 characters and the fidelity of up to 10 objects in a single workflow. * When generating text for an image, Gemini works best if you first generate the text and then ask for an image with the text. * `gemini-nano-banana-2.1` and `gemini-3.1-flash-image` Grounding with Google Search do not support using real-world images of people from web search at this time. * All generated images include a [SynthID watermark](https://ai.google.dev/responsible/docs/safeguards/synthid). ## Optional configurations {% id="optional-configurations" %} You can optionally configure the output format, aspect ratio, and image size using the `response_format` parameter. ### Output format {% id="output-format" %} The model defaults to returning both text and image responses. You can configure the response to return only the generated images (omitting the conversational text) by specifying an image format in the `response_format` parameter. To request multiple modalities (for example, both text and the generated image), pass an array of format entries to `response_format` instead. {% tabs %} {% tab label="Python" %} ```python interaction = client.interactions.create( model="gemini-nano-banana-2.1", input="Write a short poem about a starry night and generate an image of it.", response_format=[ {"type": "text"}, {"type": "image"}, ], ) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: "Write a short poem about a starry night and generate an image of it.", response_format: [ { type: "text" }, { type: "image" }, ], }); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormat; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ResponseFormat; import com.google.genai.gaos.models.interactions.TextResponseFormat; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; import java.util.Arrays; Client client = new Client(); CreateModelInteractionResponseFormat format = CreateModelInteractionResponseFormat.of( Arrays.asList( ResponseFormat.of(TextResponseFormat.builder().build()), ResponseFormat.of(ImageResponseFormat.builder().build()))); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input( InteractionsInput.of( "Write a short poem about a starry night and generate an image of it.")) .responseFormat(format) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "log" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } format := interactions.NewCreateModelInteractionResponseFormat([]interactions.ResponseFormat{ interactions.NewResponseFormat(interactions.TextResponseFormat{}), interactions.NewResponseFormat(interactions.ImageResponseFormat{}), }) res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput("Write a short poem about a starry night and generate an image of it."), ResponseFormat: genai.Ptr(format), }), }) if err != nil { log.Fatal(err) } _ = res } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -H "Api-Revision: 2026-05-20" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "Write a short poem about a starry night and generate an image of it.", "response_format": [ { "type": "text" }, { "type": "image" } ] }' ``` {% /tab %} {% /tabs %} ### Aspect ratios and image size {% id="aspect-ratios-and-image-size" %} By default, the model matches the output image size to that of your input image, or otherwise generates 1:1 squares. You can control the aspect ratio and the size of the output image using the `aspect_ratio` and `image_size` fields under `response_format` when `type` is set to `"image"`. {% tabs %} {% tab label="Python" %} ```python interaction = client.interactions.create( model="gemini-nano-banana-2.1", input=prompt, response_format={ "type": "image", "aspect_ratio": "16:9", "image_size": "2K", }, ) ``` {% /tab %} {% tab label="JavaScript" %} ```javascript const interaction = await ai.interactions.create({ model: "gemini-nano-banana-2.1", input: prompt, response_format: { type: "image", aspect_ratio: "16:9", image_size: "2K", }, }); ``` {% /tab %} {% tab label="Java" %} ```java import com.google.genai.Client; import com.google.genai.gaos.models.interactions.CreateModelInteraction; import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormat; import com.google.genai.gaos.models.interactions.ImageResponseFormatAspectRatio; import com.google.genai.gaos.models.interactions.ImageResponseFormatImageSize; import com.google.genai.gaos.models.interactions.Interaction; import com.google.genai.gaos.models.interactions.InteractionsInput; import com.google.genai.gaos.models.interactions.Model; import com.google.genai.gaos.models.interactions.ResponseFormat; import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; Client client = new Client(); String prompt = "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"; CreateModelInteractionResponseFormat format = CreateModelInteractionResponseFormat.of( ResponseFormat.of( ImageResponseFormat.builder() .aspectRatio(ImageResponseFormatAspectRatio.of("16:9")) .imageSize(ImageResponseFormatImageSize.TWO_K) .build())); CreateModelInteraction params = CreateModelInteraction.builder() .model(Model.of("gemini-nano-banana-2.1")) .input(InteractionsInput.of(prompt)) .responseFormat(format) .build(); Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get(); ``` {% /tab %} {% tab label="Go" %} ```go package main import ( "context" "log" "google.golang.org/genai" "google.golang.org/genai/interactions/models/interactions" "google.golang.org/genai/interactions/models/operations" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, nil) if err != nil { log.Fatal(err) } prompt := "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme" format := interactions.NewCreateModelInteractionResponseFormat( interactions.NewResponseFormat(interactions.ImageResponseFormat{ AspectRatio: interactions.ImageResponseFormatAspectRatio("16:9").ToPointer(), ImageSize: interactions.ImageResponseFormatImageSizeTwoK.ToPointer(), }), ) res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{ Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{ Model: interactions.Model("gemini-nano-banana-2.1"), Input: interactions.NewInteractionsInput(prompt), ResponseFormat: genai.Ptr(format), }), }) if err != nil { log.Fatal(err) } _ = res } ``` {% /tab %} {% tab label="REST" %} ```bash curl -s -X POST \ "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -H "Api-Revision: 2026-05-20" \ -d '{ "model": "gemini-nano-banana-2.1", "input": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme", "response_format": { "type": "image", "aspect_ratio": "16:9", "image_size": "2K" } }' ``` {% /tab %} {% /tabs %} The different ratios available and the size of the image generated are listed in the following tables: {% tabs %} {% tab label="Nano Banana 2.1" %} {% table %} * Aspect ratio {% align="left" %} * 1K resolution {% align="left" %} * 1K tokens {% align="left" %} * 2K resolution {% align="left" %} * 2K tokens {% align="left" %} * 4K resolution {% align="left" %} * 4K tokens {% align="left" %} --- * **1:1** {% align="left" %} * 1024x1024 {% align="left" %} * 1120 {% align="left" %} * 2048x2048 {% align="left" %} * 1680 {% align="left" %} * 4096x4096 {% align="left" %} * 2520 {% align="left" %} --- * **1:4** {% align="left" %} * 512x2048 {% align="left" %} * 1120 {% align="left" %} * 1024x4096 {% align="left" %} * 1680 {% align="left" %} * 2048x8192 {% align="left" %} * 2520 {% align="left" %} --- * **1:8** {% align="left" %} * 384x3072 {% align="left" %} * 1120 {% align="left" %} * 768x6144 {% align="left" %} * 1680 {% align="left" %} * 1536x12288 {% align="left" %} * 2520 {% align="left" %} --- * **2:3** {% align="left" %} * 848x1264 {% align="left" %} * 1120 {% align="left" %} * 1696x2528 {% align="left" %} * 1680 {% align="left" %} * 3392x5056 {% align="left" %} * 2520 {% align="left" %} --- * **3:2** {% align="left" %} * 1264x848 {% align="left" %} * 1120 {% align="left" %} * 2528x1696 {% align="left" %} * 1680 {% align="left" %} * 5056x3392 {% align="left" %} * 2520 {% align="left" %} --- * **3:4** {% align="left" %} * 896x1200 {% align="left" %} * 1120 {% align="left" %} * 1792x2400 {% align="left" %} * 1680 {% align="left" %} * 3584x4800 {% align="left" %} * 2520 {% align="left" %} --- * **4:1** {% align="left" %} * 2048x512 {% align="left" %} * 1120 {% align="left" %} * 4096x1024 {% align="left" %} * 1680 {% align="left" %} * 8192x2048 {% align="left" %} * 2520 {% align="left" %} --- * **4:3** {% align="left" %} * 1200x896 {% align="left" %} * 1120 {% align="left" %} * 2400x1792 {% align="left" %} * 1680 {% align="left" %} * 4800x3584 {% align="left" %} * 2520 {% align="left" %} --- * **4:5** {% align="left" %} * 928x1152 {% align="left" %} * 1120 {% align="left" %} * 1856x2304 {% align="left" %} * 1680 {% align="left" %} * 3712x4608 {% align="left" %} * 2520 {% align="left" %} --- * **5:4** {% align="left" %} * 1152x928 {% align="left" %} * 1120 {% align="left" %} * 2304x1856 {% align="left" %} * 1680 {% align="left" %} * 4608x3712 {% align="left" %} * 2520 {% align="left" %} --- * **8:1** {% align="left" %} * 3072x384 {% align="left" %} * 1120 {% align="left" %} * 6144x768 {% align="left" %} * 1680 {% align="left" %} * 12288x1536 {% align="left" %} * 2520 {% align="left" %} --- * **9:16** {% align="left" %} * 768x1376 {% align="left" %} * 1120 {% align="left" %} * 1536x2752 {% align="left" %} * 1680 {% align="left" %} * 3072x5504 {% align="left" %} * 2520 {% align="left" %} --- * **16:9** {% align="left" %} * 1376x768 {% align="left" %} * 1120 {% align="left" %} * 2752x1536 {% align="left" %} * 1680 {% align="left" %} * 5504x3072 {% align="left" %} * 2520 {% align="left" %} --- * **21:9** {% align="left" %} * 1584x672 {% align="left" %} * 1120 {% align="left" %} * 3168x1344 {% align="left" %} * 1680 {% align="left" %} * 6336x2688 {% align="left" %} * 2520 {% align="left" %} {% /table %} {% /tab %} {% tab label="3.1 Flash Image" %} {% table %} * Aspect ratio {% align="left" %} * 512px resolution {% align="left" %} * 0.5K tokens {% align="left" %} * 1K resolution {% align="left" %} * 1K tokens {% align="left" %} * 2K resolution {% align="left" %} * 2K tokens {% align="left" %} * 4K resolution {% align="left" %} * 4K tokens {% align="left" %} --- * **1:1** {% align="left" %} * 512x512 {% align="left" %} * 747 {% align="left" %} * 1024x1024 {% align="left" %} * 1120 {% align="left" %} * 2048x2048 {% align="left" %} * 1680 {% align="left" %} * 4096x4096 {% align="left" %} * 2520 {% align="left" %} --- * **1:4** {% align="left" %} * 256x1024 {% align="left" %} * 747 {% align="left" %} * 512x2048 {% align="left" %} * 1120 {% align="left" %} * 1024x4096 {% align="left" %} * 1680 {% align="left" %} * 2048x8192 {% align="left" %} * 2520 {% align="left" %} --- * **1:8** {% align="left" %} * 192x1536 {% align="left" %} * 747 {% align="left" %} * 384x3072 {% align="left" %} * 1120 {% align="left" %} * 768x6144 {% align="left" %} * 1680 {% align="left" %} * 1536x12288 {% align="left" %} * 2520 {% align="left" %} --- * **2:3** {% align="left" %} * 424x632 {% align="left" %} * 747 {% align="left" %} * 848x1264 {% align="left" %} * 1120 {% align="left" %} * 1696x2528 {% align="left" %} * 1680 {% align="left" %} * 3392x5056 {% align="left" %} * 2520 {% align="left" %} --- * **3:2** {% align="left" %} * 632x424 {% align="left" %} * 747 {% align="left" %} * 1264x848 {% align="left" %} * 1120 {% align="left" %} * 2528x1696 {% align="left" %} * 1680 {% align="left" %} * 5056x3392 {% align="left" %} * 2520 {% align="left" %} --- * **3:4** {% align="left" %} * 448x600 {% align="left" %} * 747 {% align="left" %} * 896x1200 {% align="left" %} * 1120 {% align="left" %} * 1792x2400 {% align="left" %} * 1680 {% align="left" %} * 3584x4800 {% align="left" %} * 2520 {% align="left" %} --- * **4:1** {% align="left" %} * 1024x256 {% align="left" %} * 747 {% align="left" %} * 2048x512 {% align="left" %} * 1120 {% align="left" %} * 4096x1024 {% align="left" %} * 1680 {% align="left" %} * 8192x2048 {% align="left" %} * 2520 {% align="left" %} --- * **4:3** {% align="left" %} * 600x448 {% align="left" %} * 747 {% align="left" %} * 1200x896 {% align="left" %} * 1120 {% align="left" %} * 2400x1792 {% align="left" %} * 1680 {% align="left" %} * 4800x3584 {% align="left" %} * 2520 {% align="left" %} --- * **4:5** {% align="left" %} * 464x576 {% align="left" %} * 747 {% align="left" %} * 928x1152 {% align="left" %} * 1120 {% align="left" %} * 1856x2304 {% align="left" %} * 1680 {% align="left" %} * 3712x4608 {% align="left" %} * 2520 {% align="left" %} --- * **5:4** {% align="left" %} * 576x464 {% align="left" %} * 747 {% align="left" %} * 1152x928 {% align="left" %} * 1120 {% align="left" %} * 2304x1856 {% align="left" %} * 1680 {% align="left" %} * 4608x3712 {% align="left" %} * 2520 {% align="left" %} --- * **8:1** {% align="left" %} * 1536x192 {% align="left" %} * 747 {% align="left" %} * 3072x384 {% align="left" %} * 1120 {% align="left" %} * 6144x768 {% align="left" %} * 1680 {% align="left" %} * 12288x1536 {% align="left" %} * 2520 {% align="left" %} --- * **9:16** {% align="left" %} * 384x688 {% align="left" %} * 747 {% align="left" %} * 768x1376 {% align="left" %} * 1120 {% align="left" %} * 1536x2752 {% align="left" %} * 1680 {% align="left" %} * 3072x5504 {% align="left" %} * 2520 {% align="left" %} --- * **16:9** {% align="left" %} * 688x384 {% align="left" %} * 747 {% align="left" %} * 1376x768 {% align="left" %} * 1120 {% align="left" %} * 2752x1536 {% align="left" %} * 1680 {% align="left" %} * 5504x3072 {% align="left" %} * 2520 {% align="left" %} --- * **21:9** {% align="left" %} * 792x168 {% align="left" %} * 747 {% align="left" %} * 1584x672 {% align="left" %} * 1120 {% align="left" %} * 3168x1344 {% align="left" %} * 1680 {% align="left" %} * 6336x2688 {% align="left" %} * 2520 {% align="left" %} {% /table %} {% /tab %} {% tab label="3 Pro Image" %} {% table %} * Aspect ratio {% align="left" %} * 1K resolution {% align="left" %} * 1K tokens {% align="left" %} * 2K resolution {% align="left" %} * 2K tokens {% align="left" %} * 4K resolution {% align="left" %} * 4K tokens {% align="left" %} --- * **1:1** {% align="left" %} * 1024x1024 {% align="left" %} * 1120 {% align="left" %} * 2048x2048 {% align="left" %} * 1120 {% align="left" %} * 4096x4096 {% align="left" %} * 2000 {% align="left" %} --- * **2:3** {% align="left" %} * 848x1264 {% align="left" %} * 1120 {% align="left" %} * 1696x2528 {% align="left" %} * 1120 {% align="left" %} * 3392x5056 {% align="left" %} * 2000 {% align="left" %} --- * **3:2** {% align="left" %} * 1264x848 {% align="left" %} * 1120 {% align="left" %} * 2528x1696 {% align="left" %} * 1120 {% align="left" %} * 5056x3392 {% align="left" %} * 2000 {% align="left" %} --- * **3:4** {% align="left" %} * 896x1200 {% align="left" %} * 1120 {% align="left" %} * 1792x2400 {% align="left" %} * 1120 {% align="left" %} * 3584x4800 {% align="left" %} * 2000 {% align="left" %} --- * **4:3** {% align="left" %} * 1200x896 {% align="left" %} * 1120 {% align="left" %} * 2400x1792 {% align="left" %} * 1120 {% align="left" %} * 4800x3584 {% align="left" %} * 2000 {% align="left" %} --- * **4:5** {% align="left" %} * 928x1152 {% align="left" %} * 1120 {% align="left" %} * 1856x2304 {% align="left" %} * 1120 {% align="left" %} * 3712x4608 {% align="left" %} * 2000 {% align="left" %} --- * **5:4** {% align="left" %} * 1152x928 {% align="left" %} * 1120 {% align="left" %} * 2304x1856 {% align="left" %} * 1120 {% align="left" %} * 4608x3712 {% align="left" %} * 2000 {% align="left" %} --- * **9:16** {% align="left" %} * 768x1376 {% align="left" %} * 1120 {% align="left" %} * 1536x2752 {% align="left" %} * 1120 {% align="left" %} * 3072x5504 {% align="left" %} * 2000 {% align="left" %} --- * **16:9** {% align="left" %} * 1376x768 {% align="left" %} * 1120 {% align="left" %} * 2752x1536 {% align="left" %} * 1120 {% align="left" %} * 5504x3072 {% align="left" %} * 2000 {% align="left" %} --- * **21:9** {% align="left" %} * 1584x672 {% align="left" %} * 1120 {% align="left" %} * 3168x1344 {% align="left" %} * 1120 {% align="left" %} * 6336x2688 {% align="left" %} * 2000 {% align="left" %} {% /table %} {% /tab %} {% tab label="Gemini 2.5 Flash Image" %} {% table %} * Aspect ratio * Resolution * Tokens --- * 1:1 * 1024x1024 * 1290 --- * 2:3 * 832x1248 * 1290 --- * 3:2 * 1248x832 * 1290 --- * 3:4 * 864x1184 * 1290 --- * 4:3 * 1184x864 * 1290 --- * 4:5 * 896x1152 * 1290 --- * 5:4 * 1152x896 * 1290 --- * 9:16 * 768x1344 * 1290 --- * 16:9 * 1344x768 * 1290 --- * 21:9 * 1536x672 * 1290 {% /table %} {% /tab %} {% /tabs %} ## When to use Imagen {% id="choose-a-model" %} {% callout type="warning" %} Imagen models are shut down. Use Nano Banana models for all image generation tasks. {% /callout %} Imagen is shut down and no longer available through the Gemini API. Use Nano Banana for image generation and editing. ## What's next {% id="what-is-next" %} * Check out the [Veo guide](/docs/video) to learn how to generate videos with the Gemini API. * To learn more about Gemini models, see [Gemini models](/docs/models).