route-switch

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.

Difficulty: beginnerTime: 8 min

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

Run route-switch today

Open source, MIT licensed. One binary, one endpoint, your providers.