# OpenRouter (https://www.librechat.ai/docs/configuration/librechat_yaml/ai_endpoints/openrouter)

OpenRouter routes requests to hundreds of models from OpenAI, Anthropic, Google, Meta, Mistral, and other providers through a single OpenAI-compatible endpoint.

## Get an API key

Create an account at [openrouter.ai](https://openrouter.ai/) and generate a key from the [Keys page](https://openrouter.ai/keys). The key starts with `sk-or-v1-`. Add it to your `.env` file:

```bash filename=".env"
OPENROUTER_KEY=sk-or-v1-your-key-here
```

<Callout type="error" title="Use OPENROUTER_KEY, not OPENROUTER_API_KEY">

The variable must be named `OPENROUTER_KEY`. Naming it `OPENROUTER_API_KEY` reroutes the built-in OpenAI endpoint through OpenRouter as well, which is almost never what you want.

</Callout>

## Configuration

Add the endpoint under `endpoints.custom` in your `librechat.yaml`:

```yaml filename="librechat.yaml"
    - name: "OpenRouter"
      apiKey: "${OPENROUTER_KEY}"
      baseURL: "https://openrouter.ai/api/v1"
      models:
        default: ["meta-llama/llama-3-70b-instruct"]
        fetch: true
      titleConvo: true
      titleModel: "meta-llama/llama-3-70b-instruct"
      dropParams: ["stop"]
      modelDisplayLabel: "OpenRouter"
```

To pin a fixed model list instead of fetching the full catalog, set `fetch: false` and list the models yourself:

```yaml filename="librechat.yaml"
      models:
        default: ["anthropic/claude-3.5-sonnet", "openai/gpt-4o", "meta-llama/llama-3-70b-instruct"]
        fetch: false
```

To let each user supply their own key through the LibreChat UI instead of reading one from `.env`, set `apiKey: "user_provided"`. Users then see a key input field when they select the endpoint.

## Notes

- With `fetch: true`, LibreChat loads the full model list from OpenRouter so new models appear automatically. The `default` array is only the initial selection.
- `dropParams: ["stop"]` strips the `stop` parameter from requests. OpenRouter models use varied stop tokens, and dropping it avoids compatibility errors.
- A `402 Payment Required` response comes from OpenRouter, not LibreChat. Add credits or pick a free model in your OpenRouter account, then retry.
