Drop-in OpenAI base_url swap
Migrate an existing OpenAI client to route-switch by changing one field — the base URL — without rewriting request code or prompts.
Migrating to a gateway should not mean a rewrite. Because route-switch presents an
OpenAI-compatible /v1/chat/completions endpoint, the migration is a single field change:
the base URL your client points at.
The one-line change
Most OpenAI SDKs accept a baseURL (or base_url) override:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "http://localhost:8080/v1", // ← route-switch gateway
apiKey: process.env.RS_KEY,
});
// unchanged from here on
await client.chat.completions.create({
model: "gpt-4",
messages: [{ role: "user", content: "Summarise this ticket…" }],
});
Everything after the base URL stays the same — the method call, the message shape, streaming. What changes is where the request goes: to the gateway, which now owns routing.
What moves out of your code
Provider choice, routing strategy, and fallback are no longer if branches around SDKs. They live
in config.yaml as registered combinations — see
choosing a routing strategy. Switching from OpenAI to
Anthropic becomes a config change, not a deploy.
Where to go next
Once the swap works, capture traffic and start measuring: capture traces to DuckDB, then close the loop with MIPROv2 on traces. This is the OpenAI-compatible migration path in full.
route-switch is built by Skelf Research.
Frequently asked questions
Do I need to change my prompts to migrate?
No. The request shape stays OpenAI-compatible. If you register the prompt as a template, the gateway renders it server-side, but your existing inline prompts continue to work.
Will streaming still work after the swap?
Yes. route-switch supports OpenAI-style streaming; usage totals arrive in the final chunk, matching what your client already expects.
Related
Choosing a routing strategy
When to use round_robin, weighted, or performance_based routing across registered prompt+model+provider combinations — and how fallback fits in.
GuideRunning MIPROv2 on production traces
How route-switch closes the loop: replaying captured traces to score instruction and few-shot candidates with goptuna, then shipping the winner.
GuideCapturing traces to DuckDB
How route-switch logs every call to a per-prompt SQLite dataset and a DuckDB analytics store, and how to read per-prompt cost, latency, and success rate.