OpenRouter swaps models in two lines. Proving the swap takes an eval
Streaming usage chunks, price-based provider routing and model fallbacks raise no errors, yet each can skew your results without anyone noticing.
In brief
- According to the official documentation, changing base_url and api_key is enough for the OpenAI SDK to call OpenRouter; changing models means replacing the slug.
- The schema is very similar to the OpenAI Chat API but not identical, and by default OpenRouter load-balances across providers by price.
- An eval, with a log of the model actually used, is the evidence a client needs to trust a decision to switch.
Two lines of code, base_url and api_key, are all an application already calling the OpenAI SDK needs to change to reach hundreds of other models, according to OpenRouter’s quickstart. The documentation calls this a “drop-in” replacement.
For an FDE, that ease is both welcome and worrying. Sooner or later a client will ask to try another model, perhaps a cheaper or faster one. Switching takes five minutes, but proving that the new model does not break the product requires an eval.
An FDE therefore needs to do both: make model changes cheap through the OpenAI compatibility layer, and build an eval that shows whether a given change is worth making.
What do the two lines change?
OpenRouter, launched in early 2023, describes itself as a single endpoint to hundreds of models. The minimal example below uses the same two parameters as the quickstart, except that the model slug is read from an environment variable:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key=os.environ["OPENROUTER_API_KEY"],
)
resp = client.chat.completions.create(
model=os.environ["MODEL_SLUG"],
messages=[{"role": "user", "content": "Summarize the following ticket: ..."}],
)
The documentation says you can put any model slug in the model field. That is why the slug belongs in configuration and out of the code. When a client wants to try a new model, you edit the configuration and run the eval, without redeploying any logic.
“Drop-in” does not always mean identical
OpenRouter’s API reference says plainly that its request and response schemas are very similar to the OpenAI Chat API, with a few small differences. Conveniently, OpenRouter normalizes the schema across models and providers, so you only have to learn one.
One documented difference concerns streaming: the final chunk, which carries usage information, has a non-empty choices array, contrary to the OpenAI spec. Say the client’s code identifies the usage chunk by checking whether choices is empty.
After a move to OpenRouter, that branch may never run, and token counts go unrecorded until someone reconciles the bill.
Code that runs may still be wrong. Before changing base_url in a client’s environment, reread every place where the code parses responses itself, especially for streaming.
One slug can mean several providers
By default, OpenRouter load-balances across providers and favors lower prices. Different providers may therefore serve the same model on different calls, and today’s eval result may not be repeatable tomorrow.
Another setting is easy to miss. The require_parameters option defaults to false, so a provider that does not support a parameter in your request may silently ignore it. Set it to true and OpenRouter uses only providers that support every parameter you send.
Fallbacks also need a careful reading. You pass in an array of model IDs, and when the first model returns an error, OpenRouter automatically tries the next, so the fallback model answers in place of the primary.
Users may then receive an answer from a model you have not evaluated thoroughly. Billing follows the model actually used, and its name appears in the response.
An eval turns impressions into evidence
OpenAI’s guide defines evals as testing model outputs against style and content criteria that you specify. The process has three steps: describe the task, run it on test inputs, then analyze and iterate.
Take a hypothetical client that wants to move support-ticket summaries to a cheaper model. You assemble 50 real tickets with personal information removed, each with pass criteria, such as stating the correct order number and not inventing a refund commitment.
Suppose the current model passes 46/50 and the new one 41/50. That gap of five tickets, along with the list of the five failures, is what the client needs to see before deciding.
Each line of the eval log should also record the model that actually answered, taken from the response. If a fallback stepped in partway through, the 41/50 score measures a mixture of two models.
What to learn first
Start with the cheapest exercise: write your own parser for streaming responses and check it against the differences listed in the API reference. Then move on to the harder skill of writing eval criteria.
When reading job descriptions, look for phrases such as “multi-model”, “LLM evaluation” and “model routing”. In your résumé, replace “experience with OpenRouter” with a statement that you moved an application to another model through the OpenAI compatibility layer, with a 50-case eval behind the decision.
There is a simple test for your criteria. Take 10 outputs, have a colleague grade them strictly by your written criteria with no further explanation, and compare the results with your own grades.
If the two of you disagree on many cases, suspect the criteria before the model. Only when both graders reach the same result is a score of 46/50 or 41/50 solid enough to put in front of a client.
Was this article useful?
Thanks for the feedback!