---
title: "OpenRouter Gateway"
description: "Access hundreds of AI models through OpenRouter"
---

The OpenRouter gateway connects ChatJS to [OpenRouter](https://openrouter.ai), 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](https://openrouter.ai)
2. Go to [API Keys](https://openrouter.ai/keys) and create a key
3. Add to `.env.local`:

```bash
OPENROUTER_API_KEY=sk-or-v1-...
```

4. Set the gateway in your config:

```typescript title="chat.config.ts"
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](https://openrouter.ai/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](/features/image-generation) feature handles this automatically.

## Pricing

OpenRouter charges per-token based on the underlying model's pricing. Check [OpenRouter Pricing](https://openrouter.ai/models) for current rates.

You can set a spending limit for each API key. See [OpenRouter’s key management guide](https://openrouter.ai/docs/guides/overview/auth/management-api-keys).

## Related

- [Gateways Overview](/gateways/overview) for the full gateway comparison
- [Vercel Gateway](/gateways/vercel) for the default gateway
