The OpenRouter image generation API creates images through compatible providers. Use the dedicated Image API, inspect model capabilities, and validate returned files before adding them to your content workflow.
Generate images through a multi-model gateway
OpenRouter exposes compatible image-generation models through one account and API surface. The benefit is model choice and common billing; the trade-off is that supported parameters, output formats, dimensions, safety rules, and pricing differ by model.
Checked October 15, 2026: image models and request fields evolve quickly. Confirm them in the live catalog and official image-generation docs.
Choose a model by job
| Job | Evaluate |
|---|---|
| Blog hero | Composition, text-free layout, wide aspect |
| Product mockup | Object consistency and clean background |
| Diagram-like visual | Use code/vector tools when labels must be exact |
| Marketing concept | Style control, brand fit, licensing policy |
Do not use generative imagery for exact charts, technical diagrams, or screenshots. Create those from real data or the actual interface.
Discover a supported image model
The current dedicated Image API lists models at GET /api/v1/images/models. Inspect a model’s endpoint records for pricing and supported controls, then set OPENROUTER_IMAGE_MODEL to its ID.
Generate and save one image with Python
Install requests and Pillow. Set your API key and chosen image model as environment variables before running:
import os, base64, io
from pathlib import Path
import requests
from PIL import Image
response = requests.post(
"https://openrouter.ai/api/v1/images",
headers={"Authorization": f"Bearer {os.environ['OPENROUTER_API_KEY']}"},
json={
"model": os.environ["OPENROUTER_IMAGE_MODEL"],
"prompt": "Editorial illustration of an AI gateway, navy, cyan and coral, no text or logos",
"n": 1,
},
timeout=(10, 180),
)
response.raise_for_status()
data = response.json()
if data.get("error") or not data.get("data"):
raise RuntimeError("Image generation failed or returned no image")
encoded = data["data"][0]["b64_json"]
if len(encoded) > 28_000_000:
raise ValueError("Encoded image exceeds this example's size budget")
raw = base64.b64decode(encoded, validate=True)
if len(raw) > 20_000_000:
raise ValueError("Decoded image exceeds the size budget")
with Image.open(io.BytesIO(raw)) as image:
image.verify()
with Image.open(io.BytesIO(raw)) as image:
if image.width * image.height > 25_000_000:
raise ValueError("Image exceeds the pixel budget")
image.convert("RGB").save(Path("openrouter-image.png"), "PNG")
print("Saved openrouter-image.png", data.get("usage"))
This saves to a fixed local filename. Add aspect, quality, or format options only after confirming endpoint support. Image generation uses /images; image understanding uses chat-completion content parts.
A reproducible prompt brief
- Subject: what must appear.
- Composition: camera angle and placement.
- Style: editorial, photographic, 3D, flat illustration.
- Palette: brand colors in plain language or hex where supported.
- Constraints: no logos, no text, no extra objects.
- Use: hero, thumbnail, square social card.
Subject: an AI gateway routing one request to three models.
Composition: left-to-right, generous negative space on the left.
Style: polished editorial 3D illustration.
Palette: navy, cyan, coral.
Constraints: no words, no logos, no UI screenshots.
Use: 16:9 blog hero.
Quality-control workflow
- Generate low-cost candidates.
- Reject anatomy, object, brand, or text artifacts.
- Choose one composition.
- Regenerate/refine at final dimensions.
- Add human-created text overlays afterward.
- Compress, add alt text, and record model/date/prompt.
Safety and rights
Review the model/provider terms for commercial use. Avoid requests that imitate a living artist, mislead viewers, or use a person’s likeness without permission. Label synthetic imagery when context could confuse users.
Troubleshooting
- No image returned: verify model modality and response parsing.
- Parameter rejected: the model does not support that field.
- Unreadable text: request no text and add typography later.
- Wrong aspect: use model-supported dimensions or crop after generation.
- High cost: reduce candidate count/quality and track usage per accepted asset.
OpenRouter image generation API FAQ
Can I use the same prompt with every model?
You can start there, but models interpret style and parameters differently. Maintain small model-specific prompt notes.
Should screenshots be generated?
No. Capture the real interface so readers can reproduce steps and see current controls.
Read next
See vision inputs, pricing, and the pillar guide.
Official references
Documentation reviewed 15 October 2026. Examples illustrate the request pattern; confirm model availability and account settings before use. No uptime or performance benchmark is claimed.
