OpenAI-compatible migration
route-switch is a drop-in OpenAI-compatible endpoint, so applications on the OpenAI SDK migrate by changing one base URL, after which routing, DuckDB analytics, and MIPROv2 optimization become available without a rewrite.
If your application already speaks the OpenAI SDK, route-switch is the lowest-friction way to add a gateway: it is an OpenAI-compatible endpoint. Migration is a base-URL change, and everything the gateway offers becomes available afterward without a rewrite.
Step one: the swap
const client = new OpenAI({
baseURL: "http://localhost:8080/v1", // route-switch
apiKey: process.env.RS_KEY,
});
That’s the migration. The drop-in OpenAI base_url swap guide covers streaming and edge cases.
Step two: unlock the gateway
Now that traffic flows through route-switch, layer on capability at your own pace:
- Routing across combinations and providers — choose a strategy.
- Analytics — per-prompt cost, latency, and success in DuckDB.
- Failover — automatic fallback when a combination degrades.
- Optimization — MIPROv2 on your traces.
The trade to weigh
You take on running a self-hosted binary and keeping its SQLite and DuckDB files. In exchange, your prompt, routing, analytics, and optimizer live in one process you control, and your traffic never leaves your infrastructure. If zero-ops access to a wide model catalogue matters more, a hosted aggregator like OpenRouter is the other shape.
Frequently asked questions
How much code changes to migrate?
One field: the client's base URL. Because the endpoint matches OpenAI's /v1/chat/completions contract, the rest of your request code and prompts stay as they are.
What do I get after migrating that I didn't have before?
Config-driven multi-provider routing, per-prompt cost/latency/success analytics in DuckDB, automatic fallback, and closed-loop MIPROv2 prompt optimization.
Related
Latency-aware routing
Use performance-based routing and DuckDB latency data to favor combinations that respond faster, with fallback when a provider slows down.
Use caseMulti-provider failover
Front six providers behind one endpoint, and fall back automatically when a provider combination's success rate drops below its threshold.
Use caseCost-aware routing
Bias traffic toward cheaper model combinations with weighted routing, and see per-prompt cost in DuckDB so routing decisions are grounded in real spend.