Skip to content
ChatJS
Esc
navigateopen⌘Jpreview
On this page

OpenRouter Gateway

Access hundreds of AI models through OpenRouter

The OpenRouter gateway connects ChatJS to OpenRouter, a unified API that routes to hundreds of models from OpenAI, Anthropic, Google, Meta, Mistral, and many others.

Use this gateway when you want the widest model selection or need access to models not available through Vercel.

Setup

  1. Create an account at OpenRouter
  2. Go to API Keys and create a key
  3. Add to .env.local:
OPENROUTER_API_KEY=sk-or-v1-...
  1. Set the gateway in your config:
const config: ConfigInput = {
  ai: {
    gateway: "openrouter",
    // ...
  },
};

Authentication

Variable Description
OPENROUTER_API_KEY Required. Your OpenRouter API key

Available Models

Hundreds of models from OpenAI, Anthropic, Google, Meta, Mistral, and many others. The full list is fetched at runtime and cached for 1 hour. The OpenRouter response format is automatically normalized to match the internal model schema.

Model IDs

Model IDs use the same provider/model format as other gateways. For example:

  • openai/gpt-4o
  • anthropic/claude-sonnet-4
  • google/gemini-2.5-flash
  • meta-llama/llama-4-maverick

Your existing model configuration in chat.config.ts works across gateways as long as the model IDs match. Check OpenRouter Models for the full list of available IDs.

Image Generation

OpenRouter routes image generation through multimodal language models rather than dedicated image APIs. createImageModel() returns null for this gateway.

Models with the image-generation tag (those with image in their output modalities) can still generate images inline through createLanguageModel(). The existing Image Generation feature handles this automatically.

Pricing

OpenRouter charges per-token based on the underlying model’s pricing. Check OpenRouter Pricing for current rates.

You can set spending limits in your OpenRouter dashboard.

Was this page helpful?