All field notes
Guides 8 minute read

How to migrate an OpenAI API integration without a rewrite

A staged migration plan for moving an OpenAI-style integration to a multi-model compatible endpoint.

In brief

  • Inventory used features before changing code.
  • Move provider configuration behind one boundary.
  • Cut over by traffic segment with fast rollback.
01

Inventory the real integration

Search for client construction, model IDs, response parsing, streaming, tool calls, embeddings, retry logic, and usage accounting. Documentation often describes an ideal architecture; source code reveals the actual one.

  • Endpoints and SDK methods
  • Request options
  • Streaming and error parsing
  • Model-specific prompts
  • Usage and billing assumptions
02

Create one provider boundary

Centralize base URL, credentials, default model, supported options, and response telemetry. Avoid a broad refactor: the goal is to isolate transport decisions before changing behavior.

client.tstypescript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.XPERSONA_API_KEY,
  baseURL: "https://www.xpersona.co/v1",
});

const response = await client.chat.completions.create({
  model: "gpt-5.6-terra",
  messages: [{ role: "user", content: "Review this pull request." }],
});

console.log(response.choices[0]?.message.content);
03

Replay production-shaped requests

Use scrubbed or synthetic equivalents of real task shapes. Compare output validity, tool arguments, stream completion, errors, latency, and cost. Include malformed and oversized requests so failure behavior is tested too.

04

Cut over with a rollback switch

Begin with internal traffic or a low-risk segment. Monitor both technical and product outcomes, increase gradually, and keep the old path available until the new lane is stable.

A DNS or base-URL change is not a migration plan. The plan is the evidence, staged traffic, and rollback around that change.

Frequently asked

Questions, answered plainly.

Can migration be only a base URL change?+

Basic chat integrations may need little more than a base URL, key, and model ID change, but production migration still requires behavior and error testing.

Should I change prompts during migration?+

Keep prompts stable for the first comparison. Otherwise you cannot tell whether differences came from the provider, model, or prompt rewrite.

What should trigger rollback?+

Predefine thresholds for errors, invalid outputs, latency, cost, and task success before starting the cutover.

Sources and next paths

Check the living surfaces.

Put it to work

One interface. Your choice of model.

Run the same task through live GPT, Claude, Gemini, and Xpersona models without rebuilding your client.

Try Xpersona chat
How to migrate an OpenAI API integration without a rewrite | Xpersona Blog