Reference guide for using google-genai Python library to generate images with gemini-3-pro-image-preview model...
Reference for generating images with Google's gemini-3-pro-image-preview model.
Load the appropriate reference based on the project's language:
| Language | Reference File |
|---|---|
| Python | references/python.md |
Instructions: When implementing Gemini image generation, read the corresponding language reference file for complete code patterns and examples.
| Property | Value |
|---|---|
| Model ID | gemini-3-pro-image-preview |
| Cost | ~$0.134 per image (2K) |
| Max Reference Images | 5+ (high fidelity) |
| Resolutions | 1K, 2K, 4K |
| Ratio | Use Case |
|---|---|
1:1 |
Square, social media posts |
2:3 |
Portrait photos |
3:2 |
Landscape photos |
3:4 |
Portrait, mobile screens |
4:3 |
Standard display |
4:5 |
Instagram portrait |
5:4 |
Large format |
9:16 |
Vertical video, stories |
16:9 |
Widescreen, presentations |
21:9 |
Ultra-wide, cinematic |
| Size | Resolution | Use Case |
|---|---|---|
1K |
~1024px | Thumbnails, previews |
2K |
~2048px | Standard output (recommended) |
4K |
~4096px | High-quality prints |
Important: Use uppercase "K" (not "1k", "2k", "4k").
export GOOGLE_API_KEY='your-api-key-here'
Generate images from text descriptions with configurable aspect ratio and resolution.
Pass reference images to maintain consistent style across generations. Supports up to 5+ images for high fidelity.
Modify existing images based on text instructions (add/remove elements, style changes).
Generate multiple style candidates or variations.
Bad: "cat, sunset"
Good: "A fluffy orange tabby cat sitting on a wooden fence,
watching a vibrant sunset over rolling hills.
Warm golden and pink light illuminates the scene.
Photorealistic style with soft focus background."
When using reference images, be explicit about what to transfer:
| Issue | Solution |
|---|---|
| "No image generated" | Check prompt for content policy violations; simplify prompt |
| "Invalid image_size" | Use uppercase: "1K", "2K", "4K" |
| "API key not found" | Set GOOGLE_API_KEY environment variable |
| Rate limits | Add delays between requests; use exponential backoff |
| Model | Cost per Image |
|---|---|
| gemini-3-pro-image-preview | ~$0.134 |
| gemini-2.5-flash-image | ~$0.039 |