- Go to Google AI Studio
- Click "Get API Key"
- Create a new API key or use an existing one
Windows (PowerShell):
$env:GEMINI_API_KEY = "your-api-key-here"
# To persist across sessions, add to your PowerShell profile:
Add-Content $PROFILE "`n`$env:GEMINI_API_KEY = 'your-api-key-here'"Windows (CMD):
set GEMINI_API_KEY=your-api-key-here
# To persist, use System Properties > Environment VariablesmacOS/Linux:
export GEMINI_API_KEY="your-api-key-here"
# Add to ~/.zshrc or ~/.bashrc to persist
echo 'export GEMINI_API_KEY="your-api-key-here"' >> ~/.zshrc- Model ID:
gemini-3-pro-image-preview(configurable via--modelflag orGEMINI_MODELenv var) - Endpoint:
https://generativelanguage.googleapis.com/v1beta/models/{model}:streamGenerateContent
| Size | Description |
|---|---|
512 |
512x512 pixels - Fast, good for icons/thumbnails |
1K |
1024x1024 pixels - Default, balanced quality/speed |
2K |
2048x2048 pixels - High resolution, slower |
python scripts/generate_image.py <prompt> [output_path] [--size SIZE]| Parameter | Required | Default | Description |
|---|---|---|---|
prompt |
Yes | - | Text description of desired image |
output_path |
No | ./generated-image.png |
Where to save the image |
--size |
No | 1K |
Image size (512, 1K, or 2K) |
| Variable | Required | Default | Description |
|---|---|---|---|
GEMINI_API_KEY |
Yes | - | Your Google Gemini API key |
IMAGE_SIZE |
No | 1K |
Image size (512, 1K, or 2K) |
python scripts/generate_image.py "A serene mountain landscape at dawn"python scripts/generate_image.py "Minimalist logo design" "./assets/logo.png"python scripts/generate_image.py --size 2K "Detailed portrait" "./high-res.png"python scripts/generate_image.py --size 512 "Simple icon" "./icon.png"- Be specific: "A red sports car" vs "A cherry red 1967 Mustang convertible"
- Include style: "in watercolor style", "photorealistic", "minimalist flat design"
- Mention lighting: "golden hour lighting", "soft diffused light", "dramatic shadows"
- Specify composition: "close-up", "wide angle", "from above", "centered"
These techniques produce significantly better results for photorealistic and professional imagery:
Include specific photography parameters for authentic looks:
- Lens focal length: "85mm f/1.4 lens", "50mm prime", "35mm wide angle"
- Aperture: "shallow depth of field at f/1.8", "deep focus at f/8"
- Camera angle: "eye-level shot", "low angle looking up", "3/4 profile view"
Example: "Portrait shot with 85mm f/1.4 lens, shallow depth of field, subject sharp against soft bokeh background"
Specify complete lighting setups for professional results:
- Three-point lighting: key light, fill light, rim/back light
- Catchlights: reflections in eyes for portraits
- Shadow quality: "soft shadows", "dramatic hard shadows", "subtle rim light"
Example: "Professional headshot with three-point lighting setup, soft key light from left, subtle fill light, rim light for hair separation, visible catchlights in eyes"
Reference specific film stocks or eras for authentic period looks:
- Film stocks: "Kodak Portra 400 color palette", "Fujifilm Pro 400H tones", "Kodak Tri-X grain"
- Era aesthetics: "1990s disposable camera quality", "early-2000s digital camera look", "1970s Polaroid style"
- Grain and texture: "subtle film grain", "realistic sensor noise"
Example: "Casual portrait with Kodak Portra 400 color tones, natural film grain, 1990s aesthetic, soft warm highlights"
When generating or editing images with faces, explicitly state preservation requirements:
"Keep the facial features exactly consistent""Preserve original face structure and proportions""Do not alter or change the face"
Add realistic texture specifications:
- Skin: "natural skin texture with visible pores", "subtle skin imperfections"
- Fabric: "fine wool texture visible", "silk sheen and drape"
- Surfaces: "brushed metal finish", "weathered wood grain"
Example: "Close-up portrait showing natural skin texture with visible pores, fine fabric detail on collar, realistic hair strands"
Be precise about framing and subject positioning:
- Shot types: "chest-up framing", "3/4 body shot", "full body"
- Positioning: "centered subject", "rule of thirds placement", "mirror selfie angle"
- Aspect ratio context: "portrait orientation", "landscape format", "square crop"
UI/Frontend:
- "A modern dashboard UI mockup with dark theme, showing analytics charts"
- "Clean minimalist app icon for a task management app, rounded square shape"
- "Hero image for a SaaS landing page, abstract gradient with geometric shapes"
Documentation:
- "Simple architecture diagram showing microservices connected by arrows"
- "Flowchart illustrating user authentication process"
Placeholders:
- "Professional headshot placeholder, silhouette style, neutral gray background"
- "Product image placeholder, simple box shape with 'Image Coming Soon' text"
Marketing/Creative:
- "Isometric illustration of a modern office workspace"
- "Gradient abstract background suitable for presentation slides"
Professional Portraits (using advanced techniques):
- "Corporate headshot, 85mm f/2.8 lens, three-point studio lighting, navy blue suit, neutral gray backdrop, subtle catchlights, chest-up framing, natural skin texture"
- "Casual lifestyle portrait, Kodak Portra 400 tones, natural window light, soft shadows, 3/4 body shot, authentic film grain, early-2000s digital aesthetic"
E-commerce & Product Photography:
- "Product photo of leather watch, 100mm macro lens, soft diffused lighting, visible leather texture and stitching, clean white background, subtle reflection"
- "Fashion flat-lay, overhead shot, soft natural lighting, fabric texture visible, minimalist composition"
Ensure the environment variable is set in your current shell:
Windows (PowerShell):
echo $env:GEMINI_API_KEY # Should show your keymacOS/Linux:
echo $GEMINI_API_KEY # Should show your key- Check your prompt for special characters that may break JSON
- Ensure the prompt isn't empty
- Verify API key is valid
- Rate limited - wait a moment and retry
- Consider upgrading your API quota
- The model may have refused the prompt (content policy)
- Try rephrasing the prompt
- Check if the model returned an error message in the response
- Ensure Python 3.6+ is installed
- Check if the full response was received (network issues)
- Verify output path is writable
- Make sure Python is in your PATH
- Use forward slashes or escaped backslashes in paths
Check Google AI pricing for current Gemini API costs. Image generation typically costs more than text generation.
- Maximum prompt length varies by model
- Some content types may be restricted by Google's content policy
- Generated images are subject to Google's terms of service
- Rate limits apply based on your API tier