OpenRouter
Configure OpenRouter as a custom endpoint in LibreChat.
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 and generate a key from the Keys page. The key starts with sk-or-v1-. Add it to your .env file:
OPENROUTER_KEY=sk-or-v1-your-key-hereUse 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.
Configuration
Add the endpoint under endpoints.custom in your 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:
models:
default: ["anthropic/claude-3.5-sonnet", "openai/gpt-4o", "meta-llama/llama-3-70b-instruct"]
fetch: falseTo 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. Thedefaultarray is only the initial selection. dropParams: ["stop"]strips thestopparameter from requests. OpenRouter models use varied stop tokens, and dropping it avoids compatibility errors.- A
402 Payment Requiredresponse comes from OpenRouter, not LibreChat. Add credits or pick a free model in your OpenRouter account, then retry.
How is this guide?