Back to Eliza

OpenRouter Plugin

packages/docs/plugin-registry/llm/openrouter.md

2.0.16.1 KB
Original Source

The OpenRouter plugin connects Eliza agents to OpenRouter's canonical inference gateway, providing access to over 200 models from all major providers through a single API key and endpoint.

Package: @elizaos/plugin-openrouter

Eliza: pinned version and upstream bundle bug

In the Eliza monorepo, @elizaos/plugin-openrouter is pinned to 2.0.0-alpha.13 (exact version in root package.json, reflected in bun.lock).

Why pin

  • 2.0.0-alpha.12 on npm is a bad publish: the Node and browser ESM bundles are truncated. They include only rolled-up config helpers; the main plugin object is missing, yet the file still exports openrouterPlugin and a default alias. Why runtime fails: Bun (and any strict tooling) tries to load that file and errors because those bindings are never declared in the module.
  • Why not ^2.0.0-alpha.10: Semver ranges can float to alpha.12, which breaks bun install / lockfile refresh for everyone using OpenRouter.
  • Why we do not patch this in patch-deps.mjs: Unlike a wrong export name in an otherwise complete file, this tarball omits the entire implementation chunk. A postinstall string replace cannot invent the plugin; the safe fix is use a good version.

When to remove the pin

After upstream publishes a fixed version, verify dist/node/index.node.js contains the full plugin (hundreds of lines, not ~80) and that bun build …/index.node.js --target=bun succeeds, then bump and relax the range if desired.

Reference: Plugin resolution — pinned OpenRouter.

Installation

bash
eliza plugins install @elizaos/plugin-openrouter

Auto-Enable

The plugin auto-enables when OPENROUTER_API_KEY is present:

bash
export OPENROUTER_API_KEY=sk-or-...

Configuration

Environment VariableRequiredDescription
OPENROUTER_API_KEYYesOpenRouter API key from openrouter.ai
OPENROUTER_BASE_URLNoCustom base URL for the OpenRouter API
OPENROUTER_BROWSER_BASE_URLNoBrowser-only proxy endpoint base URL
OPENROUTER_SMALL_MODELNoOverride the small model identifier
OPENROUTER_LARGE_MODELNoOverride the large model identifier
SMALL_MODELNoGlobal alias to override the small model
LARGE_MODELNoGlobal alias to override the large model
OPENROUTER_EMBEDDING_MODELNoOverride the embedding model identifier
EMBEDDING_MODELNoGlobal alias to override the embedding model
OPENROUTER_EMBEDDING_DIMENSIONSNoOverride embedding vector dimensions
EMBEDDING_DIMENSIONSNoGlobal alias for embedding dimensions
OPENROUTER_IMAGE_MODELNoOverride the image model identifier
IMAGE_MODELNoGlobal alias for the image model
OPENROUTER_IMAGE_GENERATION_MODELNoOverride the image generation model
IMAGE_GENERATION_MODELNoGlobal alias for the image generation model
OPENROUTER_AUTO_CLEANUP_IMAGESNoAutomatically clean up generated images
OPENROUTER_TOOL_EXECUTION_MAX_STEPSNoMaximum tool execution steps

eliza.json Example

json
{
  "auth": {
    "profiles": {
      "default": {
        "provider": "openrouter",
        "model": "anthropic/claude-sonnet-4.6"
      }
    }
  }
}

Supported Models

OpenRouter provides access to models from all major providers. Use the full provider-prefixed model ID:

OpenAI via OpenRouter

Model IDDescription
openai/gpt-5GPT-5 flagship multimodal
openai/gpt-5-miniFast and efficient
openai/gpt-4oGPT-4o multimodal
openai/o3-miniFast reasoning

Anthropic via OpenRouter

Model IDDescription
anthropic/claude-opus-4.7Most capable Claude
anthropic/claude-sonnet-4.6Balanced Claude
anthropic/claude-haiku-4.5Fastest Claude

OpenAI via OpenRouter

Model IDDescription
openai/gpt-oss-120bGPT-OSS 120B

Google via OpenRouter

Model IDDescription
google/gemini-2.5-proGemini 2.5 Pro
google/gemini-2.5-flashGemini 2.5 Flash

Browse all models at openrouter.ai/models.

Model Type Mapping

elizaOS Model TypeDefault OpenRouter Model
TEXT_SMALLgoogle/gemini-2.0-flash-001
TEXT_LARGEgoogle/gemini-2.5-flash
IMAGEx-ai/grok-2-vision-1212
IMAGE_GENERATIONgoogle/gemini-2.5-flash-image-preview
TEXT_EMBEDDINGopenai/text-embedding-3-small

Features

  • Single API key for 200+ models
  • Automatic fallback to backup providers when primary is unavailable
  • Cost optimization — routes to cheapest available provider
  • Model comparison and A/B testing
  • Usage analytics dashboard
  • Streaming responses
  • OpenAI-compatible API format
  • Free models available (community tier)

Provider Routing

OpenRouter supports routing preferences for cost, latency, or throughput:

json
{
  "auth": {
    "profiles": {
      "default": {
        "provider": "openrouter",
        "model": "anthropic/claude-sonnet-4.6",
        "providerPreferences": {
          "order": ["Anthropic", "AWS Bedrock"],
          "allowFallbacks": true
        }
      }
    }
  }
}

Free Models

OpenRouter offers free access to a selection of open-source models (rate-limited):

  • openai/gpt-oss-120b:free
  • mistralai/mistral-7b-instruct:free

Rate Limits and Pricing

Pricing is per-model and varies by provider. OpenRouter charges the same rates as the underlying provider plus a small markup on some models.

See openrouter.ai/docs#limits for rate limit details.