OpenRouter Image Generation
by @yangwenyu2
Generate images using Google Gemini via OpenRouter API. Supports text-to-image and reference-image-guided generation. Use when the user asks to generate, cre...
clawhub install openrouter-image-genπ About This Skill
name: gemini-image-gen description: Generate images using Google Gemini via OpenRouter API. Supports text-to-image and reference-image-guided generation. Use when the user asks to generate, create, draw, or design images/illustrations/covers/avatars.
Gemini Image Generation
Generate images via google/gemini-3.1-flash-image-preview on OpenRouter. Cheap ($0.25/M in, $1.5/M out), fast, good quality.
Quick Start
python3 scripts/generate.py "a watercolor illustration of a cozy cafΓ©" -o output.png
With reference image (style/character guidance):
python3 scripts/generate.py "same character but waving hello" -o wave.png --ref reference.png
Script path: skills/gemini-image-gen/scripts/generate.py
Requirements
OPENROUTER_API_KEY environment variable (or --api-key flag)How It Works
1. Calls OpenRouter /chat/completions with modalities: ["text", "image"]
2. Optionally encodes a reference image as base64 in the message
3. Extracts generated image from choices[0].message.images[0].image_url.url (data:image/png;base64,...)
4. Decodes and saves to output path
Prompt Engineering Tips (from experience)
Aspect Ratio & Composition
Character Consistency
--ref, describe the character features explicitly in the prompt AND provide the reference imageStyle Control
Text in Images
Common Pitfalls
Sending Images on Feishu
β οΈ Critical: Images must be saved to a path within localRoots (typically your OpenClaw workspace dir). /tmp is NOT whitelisted on Feishu.
# Save to workspace, not /tmp
output_path = "my_image.png" # relative to workspaceSend via message tool:
media: "file:///my_image.png"
(use 'media' parameter, NOT 'filePath')
After sending, clean up temporary images to avoid workspace clutter.
Advanced: Calling from Python (without CLI)
import os, sys
sys.path.insert(0, "skills/gemini-image-gen/scripts")
from generate import generategenerate(
prompt="a cute robot reading a philosophy book",
output="robot.png",
ref_image=None, # or path to reference image
)
Model Alternatives
| Model | Cost | Notes |
|-------|------|-------|
| google/gemini-3.1-flash-image-preview | $0.25/$1.5 per M tokens | Default. Best balance of cost and quality |
| google/gemini-3.1-pro-preview | $2/$12 per M tokens | Higher quality but 8x more expensive |
| openai/gpt-image-1 | varies | OpenAI's image model, different API format β not supported by this script |
Troubleshooting
.debug.json file created alongside output. Usually means the prompt triggered safety filters or the model returned text-only.π‘ Examples
python3 scripts/generate.py "a watercolor illustration of a cozy cafΓ©" -o output.png
With reference image (style/character guidance):
python3 scripts/generate.py "same character but waving hello" -o wave.png --ref reference.png
Script path: skills/gemini-image-gen/scripts/generate.py
π Tips & Best Practices
.debug.json file created alongside output. Usually means the prompt triggered safety filters or the model returned text-only.