Skip to content

Chapter 5: Migration and Cutover

A migration replaces a component the customer has tuned prompts against for months. Those prompts implicitly encode the incumbent’s chat template, its sampling defaults, and its quirks. Moving production traffic from a closed API (OpenAI, Anthropic, or another provider) to an open model on a new endpoint is therefore less about the endpoint and more about dependencies nobody wrote down. The work is to make those implicit dependencies explicit through an inventory and an audit, to prove the replacement on real traffic without exposing users (shadow traffic), and then to expose users gradually with an automatic way back (canary and rollback).

Concepts from other sections (18)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

Most migrations fail on quality, not latency, and most quality failures are formatting rather than model capability: the chat template, stop tokens, sampling defaults, and tool-call parsing. An OpenAI-compatible endpoint makes the code change one line; it does not make the behavior identical, so every parameter must be audited.

This chapter follows a successful POC from POC and Evaluation. It gives you a nine-step playbook, the template and parameter audit, the mechanics of shadow, canary, cutover, and rollback, and ends with a failure-mode table to use when something goes wrong. In practice an FDE leads with the customer’s engineering owner; at most companies this is where an SE hands off.

Learning objectives

  • Run a migration through inventory, endpoint swap, audit, eval parity, prompt adaptation, shadow, canary, cutover, and a tested rollback.
  • Audit the template and parameter differences (chat template, BOS, stop tokens, sampling, tool calls, structured output, reasoning tokens, tokenizer, context length) that cause most regressions.
  • Design shadow traffic and canary steps with numeric, automatic rollback triggers and sticky routing.
  • Diagnose common post-migration symptoms from a failure-mode table, and know when to escalate.

You need a passed POC and the eval parity method from POC and Evaluation. The primary reference is Model Loading: Tokenizers and Chat Templates in AI Engineering, where template and tokenizer depth lives. Supplements are the chapters on deprecation and large-scale changes in Software Engineering at Google (free), LLM Evaluation for parity checks, and Serving & Load for the latency rows of the failure table.

To build intuition before an engagement, point an OpenAI SDK client at a local vllm serve running a small instruct model, and send the same request with and without an explicit temperature and top_p; note what changes. Then render a chat template locally from a model’s tokenizer_config.json, compare the token IDs with what the server reports, and find one way they could differ.

A migration runs in nine steps, each with a condition that says it is done:

StepActionDone when
1. InventoryList every call site: model, parameters, features used (tools, JSON mode, logprobs, n, vision, seed)Spreadsheet with every call site and its parameters
2. Endpoint swapPoint the OpenAI-compatible client at the new base_url and model name behind a feature flagA single request succeeds through the customer’s real code path
3. Template and parameter auditCheck every item in Template and parameter differencesEvery item checked and noted
4. Eval parityRun the customer’s eval on incumbent and candidate with identical inputs; diff per case, not just aggregate (Eval parity against the incumbent)Delta inside the agreed tolerance; every golden case passes; regressions read by a human
5. Prompt adaptationFix regressions by prompt changes first, fine-tune only if prompt changes plateauDelta inside tolerance or a scoped fine-tune proposal
6. Shadow trafficMirror a slice of production to the candidate, discard responses, log latency, errors, and outputs3+ days covering a weekly peak; no new error classes; latency within SLO
7. CanaryRoute 1%, 10%, 50% of real traffic with automatic rollback triggers on error rate and latencyEach step holds for an agreed period with product metrics flat
8. Cutover100% to candidate; keep incumbent credentials and code path liveTwo weeks clean
9. Rollback planFlag flip back to incumbent, tested during canary, with a named ownerRollback executed once in staging and timed

The steps are not strictly linear. Eval parity loops through prompt adaptation until regressions are inside tolerance, and a canary trigger sends you back to the audit:

flowchart LR
    I["Inventory"] --> S["Endpoint swap<br/>behind a flag"]
    S --> A["Template and<br/>parameter audit"]
    A --> E["Eval parity"]
    E -->|"regressions"| PA["Prompt adaptation"]
    PA --> E
    E -->|"inside tolerance"| SH["Shadow traffic"]
    SH --> C["Canary 1% / 10% / 50%"]
    C -->|"trigger fires"| RB["Rollback to incumbent"]
    RB --> A
    C -->|"metrics flat"| CO["Cutover 100%"]
    CO -->|"two weeks clean"| D["Decommission incumbent path"]

Step 3 is where most migrations are won or lost. Each item below is a place where an OpenAI-compatible endpoint can behave differently from the incumbent while accepting the same request:

ItemWhat goes wrongCheck
Chat templateServer applies a different template than the model was trained with; system prompt dropped or merged into the first user turnRender the template locally from the model’s tokenizer_config.json and compare to server-side token IDs
Duplicate BOSClient prepends BOS and the template adds anotherInspect the first token IDs of a rendered prompt
Stop tokensGeneration runs past the turn end, or stops early on a token that appears in contentCompare eos_token_id lists in generation_config.json versus server config
Sampling defaultsIncumbent default temperature differs from the model card’s recommended settings; top_p, top_k, repetition penalty unsetPin every sampling parameter explicitly in client code
Tool call formatModel emits tool calls in its native format; parser on the server does not match the model familyRun every tool-using eval case and assert parsed tool_calls
Structured outputJSON mode on the incumbent is not schema-constrained decoding on the new server, or vice versaValidate 100% of outputs against the schema
Reasoning tokensReasoning models emit thinking blocks the client does not strip, inflating output and costCheck for reasoning fields or tags in raw responses
TokenizerSame text, different token count: context limits, max_tokens, and cost shiftRe-count eval prompts with the new tokenizer
Context lengthServed max length is lower than the model card’sQuery the server’s model metadata; test the p99-length prompt

Once the audit and eval parity pass, the remaining steps move real traffic. Shadow traffic proves the system under real load with no user risk; the canary proves it with bounded user risk. Skip neither.

Shadow traffic runs at the gateway or in application code. Each request goes to both providers; the incumbent’s answer is returned to the user, and the candidate’s latency, errors, finish_reason, and output are logged. Sample those outputs for human or judge comparison. Shadowing has a cost: the shadowed slice is paid for twice, once per provider, so size the slice deliberately. It also has a data-handling consequence. Production prompts now reach the new vendor, so the data processing agreement and the residency and retention terms must already be signed (see Commercials and Security).

Canary triggers are numbers agreed in advance: an error rate above X, TTFT p95 above the SLO for Y minutes, or a product metric (thumbs-down rate, escalation rate) moving by more than Z. Automatic triggers beat manual ones at 2 a.m. Route the canary stickily, by user or session rather than per request, so a single conversation does not switch models mid-thread.

Cutover is a flag value, not a deploy, and the incumbent path stays deployable. Keep the incumbent’s credentials and code path live for two weeks after cutover.

Rollback is rehearsed in staging during the canary, and timed. Name the person who can flip it, and make sure they have access outside business hours. A rollback plan is only real once it has been executed and timed.

When something goes wrong after a migration, the symptom usually points to a small set of causes, each with a first check:

SymptomLikely causeFirst check
Quality drop after migrationChat template mismatch or sampling defaultsDiff rendered token IDs; pin temperature and top_p
Quality drop after quantizationOutlier-sensitive layers or KV quantization on long contextEval BF16 versus FP8 on the same cases; split long and short prompts
Outputs never stop or stop mid-sentenceWrong stop tokens or max_tokens defaultInspect finish_reason distribution
Tool calls returned as plain textTool parser does not match the model familyRaw completion versus parsed response for one case
TTFT spikes when one long prompt arrivesNo chunked prefill; long prefill blocks the batchEngine config; correlate spikes with prompt length
TTFT high at moderate loadQueueing: replica past saturation, or autoscaler too slowWaiting-queue metric; compare rate to closed-loop saturation
TPOT degrades as traffic growsBatch too large for the TPOT targetRunning sequences versus TPOT curve; cap max batch
Throughput falls, then requests restartKV cache exhausted, preemption and recomputePreemption counter, KV usage near 100%
Prefix cache hit rate near zeroDynamic content (timestamp, user ID) at the start of the promptDiff the first 100 tokens of two requests
Cost overrun on dedicatedLow batch utilization: provisioned for peak, idle off-peakGPU-hours versus tokens served by hour; autoscaling floor
Cost overrun on serverlessVolume crossed the dedicated breakeven, or output tokens grew (reasoning)Monthly tokens versus breakeven; output length trend
Cold starts after idleScale-to-zero with large weightsTime from scale event to first 200; consider a minimum of one replica
Rate-limit errors at modest loadAccount tier limits, not capacityResponse headers and tier limits
Nondeterministic outputs at temperature 0Batch-dependent numericsExpected behavior; see reproducibility
Latency fine on server, slow for usersClient-side buffering, proxy without streaming, cross-region hopsMeasure TTFT at the client and the server for one request (Measuring from the customer’s region)

A useful drill is to walk this table on a local setup and write, for each row, the exact command or metric you would check first. When the first check does not explain the symptom and the remaining knobs are not yours, escalate using the template in Escalation and Handoff.

The audit in this chapter applies the chat templates, tokenizers, and generation_config.json of Model Loading, and the structured-output and latency rows draw on constrained and speculative decoding in LLM Systems & Inference. The canary and rollback mechanics are feature flags and progressive delivery, covered in Cloud Native in Systems Engineering, and the canary triggers are SLO alerts from Observability. Retiring the incumbent path is a deprecation and large-scale change of the kind discussed in Software Engineering.

At Fireworks AI, Together AI, and Baseten, “migrate from OpenAI in a week” engagements and debugging template mismatches are advanced day-to-day work. Teams using OpenRouter or LiteLLM do gateway-level provider swaps and fallbacks, and any platform team does progressive delivery of a critical dependency.

When a failure is not yours to fix, the next chapter, Escalation and Handoff, shows how to hand it on.

The deliverable is a migration runbook for Lexa (see the brief), written after the POC from the POC and Evaluation exercise passed:

  • The inventory row for the contract-review call site, with every parameter they likely use (JSON output, max_tokens, temperature).
  • The template and parameter audit filled for the chosen model, with how you would check each item.
  • A shadow plan: traffic slice, duration covering a weekday peak, what is logged, and the EU-only data path.
  • Canary steps with numeric rollback triggers, including one on JSON schema validity.
  • The rollback owner and how the rollback was tested.
  • Every canary step has an automatic trigger with a number.
  • Schema validity is checked on 100% of shadow outputs.
  • The runbook says what happens to the nightly job during cutover.
  • A peer could execute the rollback from the document alone.
  • Shadow traffic: production requests mirrored to the candidate, whose responses are logged and discarded.
  • Canary: routing a growing share of real traffic (1%, 10%, 50%) to the candidate, with automatic rollback triggers.
  • Sticky routing: assigning traffic by user or session so one conversation stays on one model.
  • Cutover: moving 100% of traffic by changing a flag value, with the incumbent path kept deployable.
  • Chat template: the model-specific format that turns a list of messages into the token sequence the model was trained on.
  • Most migrations fail on quality, and most quality failures are formatting: chat template, stop tokens, sampling defaults, tool-call parsing.
  • An OpenAI-compatible endpoint makes the code change one line, not the behavior identical; audit every parameter.
  • Shadow traffic proves the system under real load with no user risk; the canary proves it with bounded risk. Skip neither.
  • Canary triggers are numbers agreed in advance and fire automatically; routing is sticky by session.
  • A rollback plan is real only once executed and timed; keep the incumbent path live for two weeks after cutover.
  1. Why pin every sampling parameter explicitly in client code during a migration?
    AnswerThe incumbent's defaults (temperature, `top_p`, `top_k`, repetition penalty) may differ from the new server's or from the model card's recommendations. Prompts were tuned against the old defaults, so leaving them implicit changes behavior silently.
  2. Why must the DPA and residency terms be signed before shadow traffic starts?
    AnswerShadowing sends real production prompts to the new vendor, even though users never see the responses. That is processing of customer data and needs the contract in place first.
  3. The prefix cache hit rate is near zero after cutover. What is the first check?
    AnswerDiff the first 100 tokens of two requests. Dynamic content such as a timestamp or user ID at the start of the prompt breaks the shared prefix.
  4. Why route the canary by session rather than per request?
    AnswerPer-request routing could switch models mid-conversation, producing inconsistent replies and making product metrics hard to attribute. Sticky routing keeps each conversation on one model.