Nano Banana (Image generation)

Nano Banana is the name for Gemini's native image generation capabilities. It currently refers to two distinct models available in the Gemini API:

  • Nano Banana: The Gemini 2.5 Flash Image model (gemini-2.5-flash-image). This model is designed for speed and efficiency, optimized for high-volume, low-latency tasks.
  • Nano Banana Pro: The Gemini 3 Pro Image Preview model (gemini-3-pro-image-preview). This model is designed for professional asset production, utilizing advanced reasoning ("Thinking") to follow complex instructions and render high-fidelity text.

Get started

You can generate images using the generate_content method using the model name that corresponds to the version you'd like to use.

Python

fromgoogleimport genai
fromPILimport Image
client = genai.Client()
response = client.models.generate_content(
 model="gemini-2.5-flash-image",
 contents="Create a picture of a futuristic banana with neon lights in a cyberpunk city.",
)
for part in response.parts:
 if part.inline_data:
 image = part.as_image()
 image.show()

JavaScript

import{GoogleGenAI}from"@google/genai";
import*asfsfrom"node:fs";
constai=newGoogleGenAI({});
constresponse=awaitai.models.generateContent({
model:"gemini-2.5-flash-image",
contents:"Create a picture of a futuristic banana with neon lights in a cyberpunk city.",
});
for(constpartofresponse.candidates[0].content.parts){
if(part.inlineData){
constbuffer=Buffer.from(part.inlineData.data,"base64");
fs.writeFileSync("banana.png",buffer);
}
}

Go

packagemain
import(
"context"
"os"
"google.golang.org/genai"
)
funcmain(){
ctx:=context.Background()
client,err:=genai.NewClient(ctx,nil)
iferr!=nil{
// handle error
}
resp,err:=client.Models.GenerateContent(
ctx,
"gemini-2.5-flash-image",
genai.Text("Create a picture of a futuristic banana with neon lights in a cyberpunk city."),
)
for_,part:=rangeresp.Candidates[0].Content.Parts{
ifpart.InlineData!=nil{
_=os.WriteFile("banana.png",part.InlineData.Data,0644)
}
}
}

Java

importcom.google.genai.Client;
importcom.google.genai.types.GenerateContentResponse;
importcom.google.genai.types.Part;
importjava.nio.file.Files;
importjava.nio.file.Paths;
publicclass ImageGen{
publicstaticvoidmain(String[]args)throwsException{
try(Clientclient=newClient()){
GenerateContentResponseresponse=client.models.generateContent(
"gemini-2.5-flash-image",
"Create a picture of a futuristic banana with neon lights in a cyberpunk city.",
null);
for(Partpart:response.parts()){
if(part.inlineData().isPresent()){
Files.write(Paths.get("banana.png"),part.inlineData().get().data().get());
}
}
}
}
}

REST

curl"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent"\
-H"x-goog-api-key: $GEMINI_API_KEY"\
-H'Content-Type: application/json'\
-XPOST\
-d'{
 "contents": [{
 "parts": [
 {"text": "Create a picture of a futuristic banana with neon lights in a cyberpunk city."}
 ]
 }]
 }'

Learn more

For comprehensive documentation on image generation, editing, advanced prompting, and model comparisons, please see the full guide:

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年12月18日 UTC.