Image Generation
OpenRouter supports image generation via the Chat Completions and Responses endpoints. You can find the supported models, their capabilities, and pricing by filtering our model list by image output.
Model Discovery
You can find image generation models in several ways:
Via the API
Use the output_modalities query parameter on the Models API to programmatically discover image generation models:
See Models - Query Parameters for the full list of supported modality values.
On the Models Page
Visit the Models page and filter by output modalities to find models capable of image generation. Look for models that list "image" in their output modalities.
In the Chatroom
When using the Chatroom, click the Image button to automatically filter and select models with image generation capabilities. If no image-capable model is active, you’ll be prompted to add one.
API Usage
To generate images, send a request to the /api/v1/chat/completions endpoint with the modalities parameter. The value depends on the model’s capabilities:
- Models that output both text and images (e.g., Gemini): Use
modalities: ["image", "text"] - Models that only output images (e.g., Sourceful, Flux): Use
modalities: ["image"]
Basic Image Generation
Image Configuration Options
Some image generation models support additional configuration through the image_config parameter. The shared options below — aspect ratio and image size — work across many image models. Parameters that are specific to a single provider are grouped into dedicated Recraft and Sourceful sections further down.
Aspect Ratio
Set image_config.aspect_ratio to request specific aspect ratios for generated images.
Supported aspect ratios:
1:1→ 1024×1024 (default)2:3→ 832×12483:2→ 1248×8323:4→ 864×11844:3→ 1184×8644:5→ 896×11525:4→ 1152×8969:16→ 768×134416:9→ 1344×76821:9→ 1536×672
Azure MAI Image aspect ratios (supported by microsoft/mai-image-2.5):
1:1→ 1024×1024 (default)4:3→ 1024×7683:4→ 768×102416:9→ 1365×7689:16→ 768×13653:2→ 1152×7682:3→ 768×1152
Extended aspect ratios (supported by google/gemini-3.1-flash-image-preview only):
1:4→ Tall, narrow format ideal for scrolling carousels and vertical UI elements4:1→ Wide, short format for hero banners and horizontal layouts1:8→ Extra-tall format for notification headers and narrow vertical spaces8:1→ Extra-wide format for wide-format banners and panoramic layouts
Image Size
Set image_config.image_size to control the resolution of generated images.
Supported sizes:
1K→ Standard resolution (default)2K→ Higher resolution4K→ Highest resolution0.5K→ Lower resolution, optimized for efficiency (supported bygoogle/gemini-3.1-flash-image-previewonly)
You can combine both aspect_ratio and image_size in the same request:
Recraft Image Options
The parameters in this section are supported only by Recraft models. Where support is limited to a specific Recraft version (for example, V3 but not V4), that is noted on the parameter.
Strength
Set image_config.strength to control how much the output image differs from the input image during image-to-image generation. This parameter only applies when input images are provided in messages. Supported by all Recraft models (recraft/recraft-v3, recraft/recraft-v4, and recraft/recraft-v4-pro).
- Range:
0.0to1.0 - Default:
0.2 - Lower values produce outputs closer to the input image; higher values allow more creative deviation.
Example:
Text Layout (Recraft V3 only)
Use image_config.text_layout to place text at specific positions on the generated image. Each entry specifies the text to render and a bounding box defined by four corner points in normalized coordinates (0 to 1). This parameter is only supported by Recraft V3 (recraft/recraft-v3) for both text-to-image and image-to-image requests. Recraft V4 and V4 Pro do not support text_layout.
Each text layout entry is an object with:
text(required): The text string to renderbbox(required): Array of 4[x, y]coordinate pairs defining the bounding box corners (top-left, top-right, bottom-right, bottom-left), with values from 0 to 1
Example:
Style (Recraft V3 only)
Use image_config.style to apply a specific artistic style to the generated image. This parameter is only supported by Recraft V3 (recraft/recraft-v3). Recraft V4 and V4 Pro do not support styles.
See the full list of available styles in Recraft’s documentation. Note that vector styles are not supported.
Example:
RGB Colors
Use image_config.rgb_colors to specify a color palette that influences the generated image. Each color is a [r, g, b] array of three integers (0 to 255). Supported by all Recraft models (recraft/recraft-v3, recraft/recraft-v4, and recraft/recraft-v4-pro) for both text-to-image and image-to-image requests.
Example:
Background RGB Color
Use image_config.background_rgb_color to set a specific background color for the generated image. The value is a [r, g, b] array of three integers (0 to 255). Supported by all Recraft models (recraft/recraft-v3, recraft/recraft-v4, and recraft/recraft-v4-pro) for both text-to-image and image-to-image requests.
Example:
You can combine rgb_colors and background_rgb_color in the same request:
Sourceful Image Options
The parameters in this section are supported only by Sourceful models. Each parameter notes the Sourceful version (V2 or V2.5) that supports it.
Font Inputs (Riverflow V2 and newer)
Use image_config.font_inputs to render custom text with specific fonts in generated images. The text you want to render must also be included in your prompt for best results. Supported by Sourceful Riverflow V2 and newer — sourceful/riverflow-v2-fast, sourceful/riverflow-v2-pro, sourceful/riverflow-v2.5-fast, and sourceful/riverflow-v2.5-pro.
Each font input is an object with:
font_url(required): URL to the font filetext(required): Text to render with the font
Limits:
- Maximum 2 font inputs per request
- Additional cost: $0.03 per font input
Example:
Tips for best results:
- Include the text in your prompt along with details about font name, color, size, and position
- The
textparameter should match exactly what’s in your prompt - avoid extra wording or quotation marks - Use line breaks or double spaces to separate headlines and sub-headers when using the same font
- Works best with short, clear headlines and sub-headlines
Super Resolution References (Riverflow V2 only)
Use image_config.super_resolution_references to enhance low-quality elements in your input image using high-quality reference images. The output image will match the size of your input image, so use larger input images for better results. Supported by Sourceful V2 models (sourceful/riverflow-v2-fast and sourceful/riverflow-v2-pro) when using image-to-image generation (i.e., when input images are provided in messages).
Limits:
- Maximum 4 reference URLs per request
- Only works with image-to-image requests (ignored when there are no images in
messages) - Additional cost: $0.20 per reference
Example:
Tips for best results:
- Supply an input image where the elements to enhance are present but low quality
- Use larger input images for better output quality (output matches input size)
- Use high-quality reference images that show what you want the enhanced elements to look like
Scoring Prompt (Riverflow V2.5 only)
Use image_config.scoring_prompt to give the model free-form guidance it uses to evaluate and refine its own output during generation. Supported by Sourceful V2.5 models (sourceful/riverflow-v2.5-fast and sourceful/riverflow-v2.5-pro).
Example:
Scoring Rubric (Riverflow V2.5 only)
Use image_config.scoring_rubric to provide a structured set of weighted dimensions the model scores its output against. This is the structured complement to scoring_prompt — the two are independent and can be provided together in the same request (rubric for weighted dimension scoring, prompt for additional free-form guidance). Supported by Sourceful V2.5 models (sourceful/riverflow-v2.5-fast and sourceful/riverflow-v2.5-pro).
Each rubric entry is an object with:
key(required): unique machine-readable identifier for the dimensionlabel(required): human-readable namedescription(required): what this dimension evaluatesweight(required): relative importance as a positive numberpassing_score(optional): minimum acceptable scorescore_guidance(optional): array of{ "score": number, "description": string }anchors
Limits:
- 1 to 8 dimensions per request
Example:
Background Mode and Color (Riverflow V2.5 only)
Use image_config.background_mode to control how the generated image’s background is handled, and image_config.background_hex_color to set the fill color for solid backgrounds. Supported by Sourceful V2.5 models (sourceful/riverflow-v2.5-fast and sourceful/riverflow-v2.5-pro).
background_mode: one oforiginal(default — keep the generated background),transparent(remove the background), orsolid(composite onto a flat color).background_hex_color: a#RRGGBBhex string. Required whenbackground_modeissolid.
Behavior:
- Passing only
background_hex_color(withoutbackground_mode) is treated assolidwith that color. background_hex_coloris validated but then discarded fororiginalandtransparentmodes — a malformed hex string always returns a 400 regardless of mode.
Example (solid color):
Example (transparent):
Recraft uses background_rgb_color (an [r, g, b] array) to set a solid background color, whereas Sourceful V2.5 uses background_mode together with background_hex_color.
Streaming Image Generation
Image generation also works with streaming responses:
Response Format
When generating images, the assistant message includes an images field containing the generated images:
Image Format
- Format: Images are returned as base64-encoded data URLs
- Types: Typically PNG format (
data:image/png;base64,) - Multiple Images: Some models can generate multiple images in a single response
- Size: Image dimensions vary by model capabilities
Model Compatibility
Not all models support image generation. To use this feature:
- Check Output Modalities: Ensure the model has
"image"in itsoutput_modalities - Set Modalities Parameter: Use
["image", "text"]for models that output both, or["image"]for image-only models - Use Compatible Models: Examples include:
google/gemini-3.1-flash-image-preview(supports extended aspect ratios and 0.5K resolution)google/gemini-2.5-flash-imageblack-forest-labs/flux.2-problack-forest-labs/flux.2-flexsourceful/riverflow-v2-standard-preview- Other models with image generation capabilities
Best Practices
- Clear Prompts: Provide detailed descriptions for better image quality
- Model Selection: Choose models specifically designed for image generation
- Error Handling: Check for the
imagesfield in responses before processing - Rate Limits: Image generation may have different rate limits than text generation
- Storage: Consider how you’ll handle and store the base64 image data
Troubleshooting
No images in response?
- Verify the model supports image generation (
output_modalitiesincludes"image") - Ensure you’ve set the
modalitiesparameter correctly:["image", "text"]for models that output both, or["image"]for image-only models - Check that your prompt is requesting image generation
Model not found?
- Use the Models page to find available image generation models
- Filter by output modalities to see compatible models