OpenRouter Image Generation MCP Server
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
OpenRouter Image Generation MCP Server
Minimal Streamable HTTP
MCP server for LibreChat. It exposes exactly one tool, generate_image, and
talks only to OpenRouter. There is no OAuth flow and no Fireworks provider.
The OpenRouter API key is read from the Authorization: Bearer <key> header on
every MCP request. LibreChat supplies that header per user, so each generation
bills to that user's own OpenRouter account. The key is never written to disk.
Requirements
Requirement | Implementation |
OpenRouter image generation |
|
MCP over Streamable HTTP |
|
Only selected tools | Only |
Per-user API key on every call | Read from |
No OAuth | API key only; |
No Fireworks | OpenRouter only |
Docker deployable | Multi-stage |
Local testing without credits | Mock OpenRouter API and smoke test |
Related MCP server: mcp-openai-images-audio
How it works
LibreChat calls
POST /mcpwithAuthorization: Bearer <user OpenRouter key>.The server extracts the key for that request only. It does not keep a session key map and does not log the key.
generate_imagevalidates the arguments and forwards them to OpenRouter's Images API.OpenRouter returns base64 image data or a temporary URL. The server returns MCP
imagecontent for base64 results and text URLs for URL results.
The server is stateless: each MCP request creates its own server and transport instance. That keeps per-user keys isolated and makes horizontal scaling simple.
Files
File | Purpose |
| MCP server, OpenRouter client, HTTP server |
| Local OpenRouter Images API mock |
| End-to-end smoke test through MCP |
| Unit and integration tests |
| Multi-stage production image |
| Optional local/Compose deployment |
| LibreChat MCP server configuration snippet |
| Environment variable reference |
| Lint, test, build, smoke test, and publish |
| Publish tagged images to GHCR |
| npm, Docker, and GitHub Actions updates |
| Approve Dependabot PRs after checks pass |
Quick start (Node.js)
Requires Node.js 20.19 or newer (the Docker image uses Node 22).
npm ci
cp .env.example .env
npm startThe server listens on http://localhost:3333/mcp. Health check:
http://localhost:3333/health.
Docker
Build and run:
docker build -t openrouter-image-mcp:local .
docker run --rm -p 3333:3333 \
-e OPENROUTER_API_BASE_URL=https://openrouter.ai/api/v1 \
openrouter-image-mcp:localOr with Compose:
docker compose up --buildThe image runs as the unprivileged node user and includes a HEALTHCHECK
against /health. No API key is baked into the image. Per-user keys arrive from
LibreChat on each request.
LibreChat configuration
Add this under the top-level mcpServers key in librechat.yaml:
mcpServers:
openrouter-image:
type: streamable-http
url: http://openrouter-image-mcp:3333/mcp
requiresOAuth: false
timeout: 120000
initTimeout: 30000
serverInstructions: true
apiKey:
source: user
authorization_type: bearerThe URL above assumes LibreChat and this server share a Docker network. For a
LibreChat process running on the host, use http://localhost:3333/mcp.
If LibreChat's SSRF protection is enabled, allow the server address:
mcpSettings:
allowedAddresses:
- 'openrouter-image-mcp:3333'Entries are host:port without a scheme, matching the server URL.
Per-user API key (recommended)
apiKey.source: user makes LibreChat prompt each user for their own OpenRouter
key. LibreChat sends it as Authorization: Bearer <key> on every MCP request.
This is the intended deployment: each user's generations bill to their own
OpenRouter account.
The same header can be supplied through customUserVars when you need a custom
header name or more control:
mcpServers:
openrouter-image:
type: streamable-http
url: http://openrouter-image-mcp:3333/mcp
requiresOAuth: false
customUserVars:
OPENROUTER_API_KEY:
title: OpenRouter API key
description: Enter your own OpenRouter API key (sk-or-v1-...).
sensitive: true
headers:
Authorization: 'Bearer {{OPENROUTER_API_KEY}}'Admin key (single key for all users)
If you prefer one shared key, set OPENROUTER_API_KEY in the server process
environment. The server uses it only when no Authorization header is present:
docker run --rm -p 3333:3333 \
-e OPENROUTER_API_KEY=sk-or-v1-... \
openrouter-image-mcp:localPer-user headers always take precedence over the environment fallback.
LibreChat UI
Open MCP Settings in LibreChat.
Add or edit the
openrouter-imageserver.Choose API Key, then User provides key, then Bearer.
Each user enters their own OpenRouter key.
Tool schema
generate_image accepts:
Parameter | Type | Default | Notes |
| string | required | Text description of the image |
| string |
| Any OpenRouter image model slug |
| string |
|
|
| string | unset |
|
| string | unset | Tier such as |
| integer |
| 1-10; provider limits may be lower |
| string |
|
|
| string | unset |
|
| integer | unset | Reproducibility where the model supports it |
| string |
|
|
Example call from an MCP client:
{
"name": "generate_image",
"arguments": {
"prompt": "A red panda wearing a tiny astronaut helmet, studio lighting",
"model": "recraft/recraft-v4.1-flash-v2:free",
"aspect_ratio": "16:9",
"resolution": "2K",
"response_format": "b64_json"
}
}b64_json is the default because LibreChat can display the returned MCP image
content directly. Use url when you want a temporary OpenRouter URL instead.
Models
Any OpenRouter image model slug is accepted. The default model is
recraft/recraft-v4.1-flash-v2:free.
curl -sS "https://openrouter.ai/api/v1/images/models" | jqKnown model IDs at the time of writing:
Model ID | Notes |
| Default; free tier variant |
| Supports 1K-4K tiers |
Pass any model ID in the model argument. The server does not restrict the
list; OpenRouter validates the model and its parameters.
Configuration
Variable | Default | Purpose |
|
| Listen address |
|
| Listen port |
|
| API base; point at the mock for tests |
| empty | Optional admin fallback key |
|
| Model used when |
|
| OpenRouter request timeout |
|
| Maximum MCP request body size |
| empty | Comma-separated origins or |
|
| Log method, path, status, and duration only |
|
| OpenRouter |
| empty | Optional OpenRouter |
Testing
Unit and integration tests use the mock OpenRouter API. No credits are spent.
npm ci
npm test
npm run lint
npm run format:checkThe test suite covers:
health and root endpoints
CORS preflight and unknown paths
tools/listexposing onlygenerate_imagebase64 image content and URL responses
per-request API key forwarding and isolation between users
missing key rejection
arbitrary model slug passthrough
unknown argument rejection
sizeversusaspect_ratio/resolutionconflictsOpenRouter error propagation
Manual mock and smoke test
Terminal 1, start the mock:
npm run mock:openrouterTerminal 2, start the server against the mock:
OPENROUTER_API_BASE_URL=http://127.0.0.1:4010/api/v1 PORT=3333 npm startTerminal 3, run the smoke test:
MCP_URL=http://127.0.0.1:3333/mcp OPENROUTER_API_KEY=test-key npm run smokeThe smoke test checks the health endpoint, tools/list, base64 image content,
URL responses, and missing-key rejection. It also proves the per-request
Authorization header reaches OpenRouter.
GitHub Actions
The workflows mirror the openai-ocr-server project:
CI/CD (
.github/workflows/cicd.yml): runs lint and formatting, unit and integration tests, builds the Docker image, runs the container against the mock OpenRouter API, and publishesghcr.io/<owner>/<repo>on pushes tomain.Release (
.github/workflows/release.yml): on av*tag, publishesghcr.io/<owner>/<repo>images with semver tags andlatest.Dependabot (
.github/dependabot.yml): weekly npm, Docker, and GitHub Actions updates.Dependabot auto-approve: approves Dependabot PRs after checks pass.
The container smoke test uses host networking so the container can reach the
mock on 127.0.0.1:4010. No real OpenRouter key is used in CI.
Security notes
API keys are read per request and never persisted. The server does not log prompts, keys, or response bodies.
The container runs as the unprivileged
nodeuser.Request bodies are capped by
MAX_BODY_BYTES.OpenRouter calls are bounded by
OPENROUTER_TIMEOUT_MS.CORS is disabled by default. Set
CORS_ORIGINonly if a browser client needs to call the server directly. LibreChat's server-to-server calls do not need it.Put the server behind TLS and a reverse proxy in production. Do not expose it to the public internet without authentication at the proxy layer.
If you use the admin fallback key, remember that every user without a personal key will bill to that shared account.
Troubleshooting
Symptom | Fix |
| Configure |
| The user's key is invalid or revoked |
| The user's OpenRouter account has insufficient credits |
| Rate limit reached; retry later |
LibreChat cannot reach the server | Use the Docker service name and allow the address in |
| Use either |
License
MIT. See LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Generate and edit images: article covers, pet portraits, product shots. Each call spends credits.
AI image + video generation for agents: --flag prompt DSL, async generate/poll, x402 pay-per-use.
Image and video AI tools and your own pipelines, run from any AI assistant.
Generate AI images, video, voiceovers and music from Claude, ChatGPT or Cursor through 50+ models (Veo 3.1, Kling 3, Seedance, Nano Banana, GPT Image, ElevenLabs). Also image editing, upscaling, background removal, face swap, transcription, voice cloning and UGC-style video ads. Sign in with OAuth — no API key to paste. Tools are annotated (read-only vs. credit-spending); failed generations are refunded.
Related MCP Servers
- -licenseAqualityNot gradedmaintenanceEnables generating and editing images using OpenRouter's API with Gemini 2.5 Flash Image model. Supports custom aspect ratios, iterative editing, and reference images for style transfer.6137 npm-
- AlicenseAqualityDmaintenanceExposes OpenAI's gpt-image-2 and gpt-image-1.5 to Claude Code as a single tool for generating, editing, or composing images with automatic model selection.12MIT
- AlicenseAqualityDmaintenanceGives AI assistants image generation and editing capabilities through OpenRouter, supporting multiple models, style presets, variations, and batch operations.547 npm2MIT
- AlicenseAqualityCmaintenanceWraps OpenAI-compatible text-to-image APIs as MCP tools, enabling image generation directly from conversations in Claude Code, Codex, Cursor, or Claude Desktop using the user's own API key.61Apache 2.0