OpenRouter
A gateway to AI models of many providers: one API, routing, fallback models and the data on the way.
AIUsing since 2024 · Featured project: ENATIV Portfolio
- Category
- AI
- Using since
- 2024
- Featured project
- ENATIV Portfolio
In practice
I pick OpenRouter when an app should have one account and one API address for models of different providers, and choosing a model should be a setting, not a rebuild. The chat on this site, ENATIV Portfolio, reaches its model through OpenRouter. When data cannot pass through a middleman, I choose a direct contract with the provider.
What is OpenRouter?
OpenRouter is a service that exposes models of many providers through one API address. Instead of an account at each provider, you send the request to OpenRouter and name the model in it. It is also compatible with the OpenAI API: an OpenAI client works with it after a change of address and credentials, plus a model name from OpenRouter. In TypeScript you connect it through the AI SDK; this entry is about the gateway.
OpenRouter itself picks which provider serves a request for a given model. By default it weighs measured price and reliability, and a request can narrow that: give an order of providers or require those that do not collect data. When a model is unavailable, the request can move on to the next model in a list, and billing follows the model that finally answered.
- Kind
- A gateway to models of many providers
- Access
- One API and one account
How I work with OpenRouter
I start by asking which data will pass through the model, because a gateway adds a second middleman. Only when that is acceptable do I pick models. I keep the model identifier in one place, so changing it is a setting.
Data and provider settings
I read what OpenRouter and the model providers do with the content of requests. OpenRouter stores no prompts or answers unless you opt in, but the model provider has its own rules, so a request can limit routing to providers that do not collect data or keep none.
Fallback models and billing
A list of fallback models kicks in on an outage or a rate limit and bills by the model that finally answered. A fallback can cost more or sound different, so I set it deliberately and test it on the same questions as the main model. In ENATIV Portfolio the chat route uses one model and no fallback list.
Account and credentials
The account belongs to the company. Only the server environment holds the API key, and in ENATIV Portfolio the chat route, without it, answers with a
503error instead of sending the request.
When it fits, and when it doesn't
OpenRouter fits where the choice of model should stay open for the whole life of the product.
A good fit when
- An app that should use models of different providers without a separate integration with each.
- A project at the trial stage, comparing several models on the same questions.
- A feature that should survive the outage of one model thanks to a fallback list.
- A chat or assistant in a Next.js app that needs just one account on the server side.
Not a fit when
- Personal or confidential data that cannot pass through a middleman.
- A feature that relies on abilities of one model that other providers do not offer in the same shape.
- A company that already has a contract with a model provider and does not want a second party.
Calling models from code, meaning streaming and tools, needs a separate layer, described in the entry on the AI SDK. When answers should rest on your documents, that is a topic for RAG. I choose an account directly at the model provider when the data is sensitive or one model is enough. Besides OpenRouter I also integrate the native provider APIs directly, such as Anthropic, OpenAI and Gemini.
Frequently asked questions
Torn between one model provider and a gateway?
Write which data will pass through the model and how many providers you want at hand. I will say whether one OpenRouter account is enough or a direct contract is better.