For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
ModelsChatRankingsDocs
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
  • Overview
    • Quickstart
    • Principles
    • Models
    • Stripe Projects
    • FAQ
    • Report Feedback
  • Models & Routing
    • Model Fallbacks
    • Provider Selection
    • Auto Exacto
    • Private Models
  • Features
    • Workspaces
    • Presets
    • Response Caching
    • Tool Calling
      • Overview
      • Web Search
      • Web Fetch
      • Datetime
      • Image Generation
      • Fusion
    • Structured Outputs
    • Message Transforms
    • Zero Completion Insurance
    • ZDR
    • App Attribution
    • Service Tiers
    • Sovereign AI
    • Router Metadata
    • Input & Output Logging
LogoLogo
ModelsChatRankingsDocs
On this page
  • How It Works
  • Quick Start
  • Configuration
  • Response
  • Works with the Responses API
  • Pricing
  • Next Steps
FeaturesServer Tools

Image Generation

Beta
Generate images from text prompts with any model
Was this page helpful?
Previous

Fusion

Multi-model deliberation as a server tool

Next
Built with
Beta

Server tools are currently in beta. The API and behavior may change.

The openrouter:image_generation server tool enables any model to generate images from text prompts. When the model determines it needs to create an image, it calls the tool with a description. OpenRouter executes the image generation and returns the result to the model.

How It Works

  1. You include { "type": "openrouter:image_generation" } in your tools array.
  2. Based on the user’s request, the model decides whether image generation is needed and crafts a prompt.
  3. OpenRouter generates the image using the configured model (defaults to openai/gpt-5-image).
  4. The generated image URL is returned to the model.
  5. The model incorporates the image into its response. It may generate multiple images in a single request if needed.

Quick Start

1const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
2 method: 'POST',
3 headers: {
4 Authorization: 'Bearer {{API_KEY_REF}}',
5 'Content-Type': 'application/json',
6 },
7 body: JSON.stringify({
8 model: '{{MODEL}}',
9 messages: [
10 {
11 role: 'user',
12 content: 'Create an image of a futuristic city at sunset'
13 }
14 ],
15 tools: [
16 { type: 'openrouter:image_generation' }
17 ]
18 }),
19});
20
21const data = await response.json();
22console.log(data.choices[0].message.content);

Configuration

The image generation tool accepts optional parameters to customize the output:

1{
2 "type": "openrouter:image_generation",
3 "parameters": {
4 "model": "openai/gpt-5-image",
5 "quality": "high",
6 "aspect_ratio": "16:9",
7 "size": "1024x1024",
8 "background": "transparent",
9 "output_format": "png"
10 }
11}
ParameterTypeDefaultDescription
modelstringopenai/gpt-5-imageWhich image generation model to use. See available image models.
qualitystring—Image quality level (model-dependent, e.g. "low", "medium", "high")
sizestring—Image dimensions (e.g. "1024x1024", "512x512")
aspect_ratiostring—Aspect ratio (e.g. "16:9", "1:1", "4:3")
backgroundstring—Background style (e.g. "transparent", "opaque")
output_formatstring—Output format (e.g. "png", "jpeg", "webp")
output_compressionnumber—Compression level (0-100) for lossy formats
moderationstring—Content moderation level (e.g. "auto", "low")

All parameters except model are passed directly to the underlying image generation API. Available options depend on the specific model being used.

Response

When the model calls the image generation tool, it receives a response like:

1{
2 "status": "ok",
3 "imageUrl": "https://..."
4}

If generation fails, the response includes an error:

1{
2 "status": "error",
3 "error": "Generation failed due to content policy"
4}

Works with the Responses API

The image generation server tool also works with the Responses API:

1const response = await fetch('https://openrouter.ai/api/v1/responses', {
2 method: 'POST',
3 headers: {
4 Authorization: 'Bearer {{API_KEY_REF}}',
5 'Content-Type': 'application/json',
6 },
7 body: JSON.stringify({
8 model: '{{MODEL}}',
9 input: 'Generate an image of a mountain landscape',
10 tools: [
11 {
12 type: 'openrouter:image_generation',
13 parameters: { quality: 'high' }
14 }
15 ]
16 }),
17});
18
19const data = await response.json();
20console.log(data);

Pricing

Image generation pricing depends on the underlying model used:

  • openai/gpt-5-image (default): See model page
  • openai/gpt-5-image-mini: See model page
  • openai/gpt-5.4-image-2: See model page
  • Other models: See the image models list on OpenRouter

The cost is in addition to standard LLM token costs for processing the request and response.

Next Steps

  • Server Tools Overview — Learn about server tools
  • Web Search — Search the web for real-time information
  • Datetime — Get the current date and time
  • Tool Calling — Learn about user-defined tool calling