generate_image
Generate high-resolution images from text prompts with optional Google Search grounding, up to 14 reference images, and transparent background cut-outs.
Instructions
═══════════════════════════════════════════════════════════════════════════════ 🎨 GEMINI 3.1 FLASH IMAGE GENERATION ═══════════════════════════════════════════════════════════════════════════════
Supports: • Gemini 3.1 Flash Image (Nano Banana 2) - Fast, high-volume, 512px-4K
🌟 KEY CAPABILITIES: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ✓ High-Resolution Output: 512px, 1K, 2K, 4K ✓ Advanced Text Rendering: Legible text in infographics, diagrams, menus ✓ Reference Images: Up to 14 images (10 objects, 4 characters) ✓ Grounding: Google Web Search & Image Search ✓ Thinking Mode: Configurable reasoning (minimal or high) ✓ Transparent Backgrounds: one flag → ready-to-use alpha PNG/WebP cut-outs. See below — it just works. ✓ SynthID Watermarking: Invisible watermark on all images
🚀 WHY GEMINI 3.1 FLASH IS DIFFERENT: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ This isn't your old image generator. Gemini 3.1 Flash has LIVE ACCESS to Google Search and Image Search - it can find actual references for ANYTHING.
Examples: • "Way of Wade 12 latest colorway" → model finds the real shoe online • "Tony Hawk doing a kickflip" → model finds actual Tony Hawk photos • "iPhone 16 Pro Max" → generates the REAL device, not a guess • "Taylor Swift at the 2024 VMAs" → finds real reference images
Don't over-prompt! Simple descriptions work best. The model COOKS.
📋 PARAMETERS: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
► prompt (required, str): The text description. Be descriptive and specific. TIP: Less is more. "Tony Hawk kickflip" > "A man with long blonde hair wearing a skateboarding helmet doing a trick on a skateboard"
► enable_google_search (optional, bool, default: False): Enable Google Web Search for real-time data grounding. USE THIS FOR: Products, people, events, places, anything that exists NOW. The model will search for current info and generate ACCURATELY.
► enable_image_search (optional, bool, default: False): Enable Google Image Search for visual context. USE THIS FOR: Any visual reference - the model finds real images to work from. This is the "secret sauce" - it can reference actual photos of people, products, art, anything on the web.
► aspect_ratio (optional, str, default: "1:1"): OPTIONS: "1:1", "1:4", "1:8", "2:3", "3:2", "3:4", "4:1", "4:3", "4:5", "5:4", "8:1", "9:16", "16:9", "21:9"
► image_size (optional, str, default: "2K"): OPTIONS: "512px", "1K", "2K", "4K" • "512px": Fastest, lowest cost (0.5K) • "2K": Recommended balance
► output_format: "png" (default), "jpeg", "webp"
► reference_image_paths (optional, str | list[str]): Path(s) to up to 14 reference images (10 objects + 4 characters). Accepts either a single path string (e.g. "/path/to/ref.png") or a list of path strings (e.g. ["/a.png", "/b.png"]).
► thinking_level (optional, str, default: "minimal"): Controls reasoning effort: "minimal" (fast) or "high" (best quality, slower). PRO TIP: Use "high" when using Google/Image search for best results.
🧠 THINKING MODE: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Gemini 3.1 Flash uses reasoning to refine composition before generating. Use thinking_level to balance quality vs latency: • minimal: Fastest, basic prompts • high: Best quality for complex prompts, slower PRO TIP: Use "high" thinking when using Google/Image search for best results.
🪟 TRANSPARENT BACKGROUNDS — JUST SET transparent_background=True: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ✅ THIS WORKS GREAT. Set transparent_background=True and you get back a ready-to-use transparent PNG/WebP with a real alpha channel — no extra tools, no manual masking, no follow-up steps. Use it directly.
Behind the scenes this uses a TWO-PASS DIFFERENCE MATTE: the subject is rendered once on a pure WHITE background, then that image is edited to a pure BLACK background, and the two frames are combined to recover a true (fractional) alpha channel. This costs a second model call (≈2x tokens/latency) but gives materially better edges than color-keying — clean soft edges, glow, glass, and shadows, with no green halo. You don't prompt for transparency; you just ask for it.
► transparent_background (bool, default: False): Flip to True to get the transparent cut-out. That's the whole API.
► alpha_output_format (str, default: "png"): Alpha output format: "png" (default) or "webp".
► preserve_original (bool, default: True): Also keeps the pass-1 (white-background) image next to the cut-out; set False for just the transparent file.
Each image returns transparent_path (your alpha file) plus background_removed, aligned, alignment_error and post_processing_warnings so you can confirm the cut succeeded. It nails crisp-edged subjects and soft glow/glass; the one failure mode is the edit pass drifting the subject (flagged via aligned=false) — regenerate if the edges look ghosted.
📤 RESPONSE FORMAT: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Returns JSON with: { "success": true, "images": [ { "path": "/path/to/image.png", "size": 12345 } ], "metadata": { "thinking_level": "minimal", "grounding_metadata": {...} } }
⚠️ IMPORTANT - AI ASSISTANT INSTRUCTIONS: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Parse JSON to get file path: result["images"][0]["path"] (when transparent_background=True, use result["images"][0]["transparent_path"]).
Inform user of the EXACT file path.
Open image in native OS viewer using Bash:
macOS:
open "/path/to/image.png"Linux:
xdg-open "/path/to/image.png"Windows:
start "" "/path/to/image.png"
💡 Need a transparent cut-out? Don't hand-mask or reach for another tool — just call this tool with transparent_background=True and use the returned transparent_path. It's built for exactly that.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | ||
| image_size | No | 2K | |
| aspect_ratio | No | 1:1 | |
| output_format | No | png | |
| thinking_level | No | minimal | |
| preserve_original | No | ||
| alpha_output_format | No | png | |
| enable_image_search | No | ||
| response_modalities | No | ||
| enable_google_search | No | ||
| reference_image_paths | No | ||
| transparent_background | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |