How to use gemini-2.5-flash-image with Google AI Studio

Here’s the fastest way to get started with gemini-2.5-flash-image (Google’s native text-to-image & image-editing model).
1) Pick your access path
Gemini API (AI Studio) — simplest way; auth via API key. Great for apps, servers, and quick prototyping. (Google AI for Developers)
Vertex AI — GCP-managed, quotas/billing/enterprise controls; same model name. Note: preview image models are being retired; migrate to
gemini-2.5-flash-image. (Google Cloud)
2) Get an API key (AI Studio)
Create a key in Google AI Studio → “Get API key,” then set GEMINI_API_KEY in your environment. Docs + model card: (Google AI for Developers)
3) Minimal “text → image” call
cURL (Gemini API)
curl -s -X POST \
"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" \
-d '{
"contents":[{"parts":[{"text":
"A cozy, cinematic coffee shop interior at golden hour, shallow depth of field, 35mm, soft rim light"}
]}]
}'
The response includes an image as base64 in candidates[0].content.parts[].inlineData.data. (Google AI for Developers)
JavaScript (Node)
import { GoogleGenerativeAI } from "@google/generative-ai";
import fs from "fs";
const ai = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
const prompt = "Minimalist poster of a red fox in the snow, high contrast, grainy film look";
const res = await ai.models.generateContent({
model: "gemini-2.5-flash-image",
contents: prompt,
});
for (const part of res.candidates[0].content.parts) {
if (part.inlineData) {
fs.writeFileSync("output.png", Buffer.from(part.inlineData.data, "base64"));
}
}
Python
from google import genai
from google.genai import types
from io import BytesIO
from PIL import Image
client = genai.Client() # reads GOOGLE_API_KEY or similar env var
prompt = "Architectural render of a tranquil Japanese courtyard, dusk, volumetric light"
resp = client.models.generate_content(
model="gemini-2.5-flash-image",
contents=prompt,
)
image_bytes = next(
(p.inline_data.data for p in resp.candidates[0].content.parts if getattr(p, "inline_data", None)),
None,
)
if image_bytes:
img = Image.open(BytesIO(image_bytes))
img.save("courtyard.png")
4) Control output (aspect ratio, image-only, etc.)
Add a config to your call:
JS (force image-only + 16:9)
const res = await ai.models.generateContent({
model: "gemini-2.5-flash-image",
contents: "Wide cinematic landscape of Icelandic black sand beach, long exposure",
config: {
responseModalities: ["Image"],
imageConfig: { aspectRatio: "16:9" }
}
});
(Also available in Python/Go.) (Google AI for Developers)
5) Image editing / multi-image fusion
Pass input images (base64) alongside your text instruction.
cURL (edit an image)
IMG_BASE64=$(base64 -w0 input.jpg)
curl -s -X POST \
"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' \
-d "{
\"contents\": [{
\"parts\": [
{\"text\": \"Replace the sky with dramatic storm clouds; keep colors natural\"},
{\"inline_data\": {\"mime_type\":\"image/jpeg\",\"data\":\"$IMG_BASE64\"}}
]
}]
}"
You can include multiple inline_data parts to merge images (e.g., place a product into a new scene). (Google AI for Developers)
6) Prompting tips (huge quality boost)
Describe a full scene (camera, lens, lighting, mood, materials). Narrative prompts reliably beat keyword lists. The official guide includes templates for photorealistic, logo, sticker, and negative-space compositions. (Google AI for Developers)
7) Pricing, safety & watermarks
Pricing (Gemini API): blog post lists
$30 / 1M output tokens; each image ~1290 output tokens (~$0.039/image). (Check your region/account for current pricing.) (Google Developers Blog)Retirements: preview image models (
gemini-2.0-flash-preview-image-generation,gemini-2.5-flash-image-preview) retire Oct 31, 2025—usegemini-2.5-flash-image. (Google Cloud)Watermarking: Images include SynthID invisible watermark for provenance. (Google Developers Blog)
8) Vertex AI variant (if you’re on GCP)
Use the Vertex AI SDK or REST with the same model name gemini-2.5-flash-image; samples and quickstart in Google Cloud docs. (Google Cloud)
9) Common gotchas
No image file? Ensure you’re reading
inlineData.data(base64) from the first candidate and writing it as bytes. (Google AI for Developers)Only images back (no text): set
responseModalities: ['Image']. (Google AI for Developers)Sizes/ratios: use
imageConfig.aspectRatio(e.g.,"1:1","4:5","16:9"). (Google AI for Developers)
If you tell me your stack (Node, Python, or Vertex AI) and your use case (new image vs edit vs fusion), I’ll tailor a drop-in snippet for your app.






