openclaw - ✅(Solved) Fix image_generate: Add OpenRouter provider support for image generation models [1 pull requests, 2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#55066Fetched 2026-04-08 01:32:56
View on GitHub
Comments
2
Participants
3
Timeline
3
Reactions
4
Timeline (top)
commented ×2subscribed ×1

The built-in image_generate tool currently only supports Google (Gemini) and OpenAI (gpt-image-1) as image generation providers. It does not support using image generation models available through OpenRouter, even when OpenRouter is configured as the primary LLM provider.

Root Cause

The built-in image_generate tool currently only supports Google (Gemini) and OpenAI (gpt-image-1) as image generation providers. It does not support using image generation models available through OpenRouter, even when OpenRouter is configured as the primary LLM provider.

PR fix notes

PR #67668: feat(openrouter): add image generation provider

Description (problem / solution / changelog)

Summary

  • Adds image generation support to the OpenRouter extension via the OpenAI-compatible /chat/completions endpoint (modalities: ["image", "text"])
  • Implements a native image generation provider following existing provider patterns (OpenAI, Google, fal, minimax, vydra)
  • Supports generate + edit modes, multiple aspect ratios (1:1 through 21:9), and resolution hints (1K/2K/4K) via image_config
  • Handles OpenRouter's non-standard image response format (message.images[].image_url.url) with robust fallbacks for other response structures
  • Ships with Gemini image models as defaults; the provider is model-agnostic and supports any image-capable model routed through OpenRouter
  • Production-tested end-to-end on a live OpenClaw instance (running in docker, hosted on ClawBob)

Change Type

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Root Cause

  • OpenRouter does not expose image generation as a native provider in OpenClaw, despite supporting image outputs via its chat completions API
  • Its response format differs from other providers (images returned outside message.content), requiring custom parsing logic

User-visible / Behavior Changes

  • Users can now generate and edit images using OpenRouter-backed models through the image_generate tool
  • OpenRouter becomes a first-class image generation provider alongside existing native providers
  • No additional provider keys required if OpenRouter is already configured

Issues

Resolves: #55066, #50485, #55277, #55011

Repro + Verification

Environment

  • OS: Linux (Dockerized OpenClaw instance)
  • Runtime/container: OpenClaw (Coolify deployment)
  • Model/provider: openrouter/google/gemini-3-pro-image-preview
  • Integration/channel (if any): OpenRouter extension

Verified

  • Contract: plugin registers imageGenerationProviderIds and satisfies requireGenerateImage
  • Live: image-generation.runtime.live.test.ts passes for OpenRouter (generate + edit)
  • Manual: confirmed image_generate tool produces valid images with correct formats and configurations

Build Note

  • No new build issues introduced
  • Uses existing SDK HTTP helpers (postJsonRequest, assertOkOrThrowHttpError) consistent with other providers

Changed files

  • extensions/openrouter/api.ts (modified, +1/-0)
  • extensions/openrouter/image-generation-provider.ts (added, +269/-0)
  • extensions/openrouter/index.ts (modified, +2/-0)
  • extensions/openrouter/openclaw.plugin.json (modified, +2/-1)
  • extensions/openrouter/test-api.ts (modified, +1/-0)
  • src/image-generation/live-test-helpers.ts (modified, +1/-0)
  • test/helpers/plugins/plugin-registration-contract-cases.ts (modified, +2/-0)
  • test/image-generation.runtime.live.test.ts (modified, +5/-0)

Code Example

google (default gemini-3.1-flash-image-preview)
  models: gemini-3.1-flash-image-preview, gemini-3-pro-image-preview
openai (default gpt-image-1)
  models: gpt-image-1
RAW_BUFFERClick to expand / collapse

Summary

The built-in image_generate tool currently only supports Google (Gemini) and OpenAI (gpt-image-1) as image generation providers. It does not support using image generation models available through OpenRouter, even when OpenRouter is configured as the primary LLM provider.

Current Behavior

Running image_generate(action="list") returns only two providers:

google (default gemini-3.1-flash-image-preview)
  models: gemini-3.1-flash-image-preview, gemini-3-pro-image-preview
openai (default gpt-image-1)
  models: gpt-image-1

There is no way to use OpenRouter-hosted image generation models (e.g. openai/gpt-image-1, google/gemini-3.1-flash-image-preview, or other image-capable models) through the image_generate tool, even when OPENROUTER_API_KEY is set and OpenRouter is used as the default model provider.

Expected Behavior

image_generate should support OpenRouter as a provider, allowing users to:

  1. Use image generation models available on OpenRouter (e.g. openrouter/openai/gpt-image-1)
  2. Leverage existing OpenRouter API keys without needing separate provider-specific API keys
  3. Configure via agents.defaults.imageGenerationModel.primary with an openrouter/* prefix

Motivation

Many users route all their model traffic through OpenRouter for unified billing, API key management, and access to a wider selection of models. Being forced to set up separate Google/OpenAI API keys just for image generation breaks this workflow.

extent analysis

Fix Plan

To add support for OpenRouter as an image generation provider, we need to make the following changes:

  • Update the image_generate tool to recognize OpenRouter as a valid provider
  • Add support for OpenRouter API keys and model prefixes

Code Changes

# Add OpenRouter as a supported provider
SUPPORTED_PROVIDERS = ['google', 'openai', 'openrouter']

# Update the image_generate function to handle OpenRouter models
def image_generate(action, provider=None, model=None):
    if provider == 'openrouter':
        # Use the OpenRouter API key and model prefix
        api_key = os.environ.get('OPENROUTER_API_KEY')
        model_prefix = 'openrouter/'
        # ... (rest of the function remains the same)

# Update the list action to include OpenRouter models
def list_providers():
    providers = []
    for provider in SUPPORTED_PROVIDERS:
        if provider == 'openrouter':
            # List OpenRouter models using the OpenRouter API
            models = get_openrouter_models(api_key)
            providers.append({'provider': provider, 'models': models})
        # ... (rest of the function remains the same)

# Helper function to get OpenRouter models
def get_openrouter_models(api_key):
    # Use the OpenRouter API to list available models
    response = requests.get('https://api.openrouter.com/models', headers={'Authorization': f'Bearer {api_key}'})
    return [model['name'] for model in response.json()]

Configuration Changes

  • Add an openrouter prefix to the agents.defaults.imageGenerationModel.primary configuration option to use OpenRouter as the primary image generation provider.

Verification

  • Run image_generate(action="list") to verify that OpenRouter is listed as a supported provider
  • Run image_generate(action="generate", provider="openrouter", model="openai/gpt-image-1") to verify that image generation works with OpenRouter models

Extra Tips

  • Make sure to set the OPENROUTER_API_KEY environment variable to use OpenRouter as the primary image generation provider.
  • Update the documentation to reflect the new support for OpenRouter as an image generation provider.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING