Switching an application from one large language model to another is more than changing an endpoint or model name. This guide gives you a repeatable migration workflow for comparing API behavior, estimating cost and performance, testing output parity, and releasing a fallback plan without silently breaking prompts, structured responses, tool calls, or production controls.
Overview
An LLM model migration is successful when the replacement model preserves the application’s required behavior at an acceptable cost, latency, and reliability level. Exact output matching is rarely the right goal. Instead, define which behaviors must remain stable, which differences are acceptable, and which improvements would justify the change.
Start by separating your application into four layers:
- Provider layer: authentication, endpoints, SDKs, request parameters, retries, rate limits, and error formats.
- Model layer: context capacity, tokenization, reasoning behavior, multimodal support, tool calling, and structured output capabilities.
- Application layer: prompts, conversation state, retrieval logic, parsers, business rules, and user-facing fallbacks.
- Operations layer: cost monitoring, latency targets, safety checks, evaluation datasets, logging, and rollback procedures.
Do not begin with a wholesale rewrite. Put the model identifier and provider-specific configuration behind a small adapter, then run the current and candidate models against the same representative inputs. This makes it easier to distinguish a model difference from an integration defect.
Model migration comparison table
| Area | What to compare | Migration question |
|---|---|---|
| API and SDK | Endpoints, authentication, request and response objects, streaming, retries | Can the adapter normalize both providers without changing application code? |
| Prompt compatibility | System instructions, role handling, delimiters, defaults, and message limits | Does the prompt produce the same required behavior under the candidate model? |
| Structured output | JSON mode, schema support, strictness, refusals, and validation errors | What happens when the model cannot satisfy the schema? |
| Tool calling | Tool declaration format, argument serialization, parallel calls, and call identifiers | Can existing tools be validated and executed safely? |
| Tokenization | Input and output token counts, truncation, and context limits | Will existing conversations or retrieved documents fit? |
| Operations | Latency, rate limits, availability signals, errors, and usage reporting | Can the service meet the application’s throughput and response targets? |
| Economics | Input, output, cached, batch, and ancillary charges where applicable | Does the total cost per successful task improve? |
For implementation details, pair this process with a provider-neutral AI API integration guide. If your application uses schemas, review structured outputs and JSON Schema validation before changing models.
How to estimate
Estimate migration impact with the same units you use to run the application: successful tasks, requests, tokens, tool calls, and user-visible response time. A model that is cheaper per token may not be cheaper per completed task if it requires more retries, longer prompts, or additional validation work.
1. Establish the current baseline
Measure the current model over a representative period or test batch. Record:
- Requests and successful task completions
- Average and high-percentile input and output tokens
- Latency from request start to usable response
- Timeout, rate-limit, parsing, refusal, and tool-execution error rates
- Task quality scores from human review or an automated evaluation
- Cost per request and cost per successful task
A useful baseline formula is:
Cost per successful task = total model and retry cost ÷ successful tasks
Use successful tasks rather than raw requests because failures and retries are part of the real operating cost.
2. Calculate candidate cost
Keep provider rates as editable inputs rather than hard-coding them into a document or dashboard. A general estimate is:
Estimated cost = (input tokens ÷ billing unit × input rate) + (output tokens ÷ billing unit × output rate) + other applicable charges
Then account for retries:
Expected cost per task = estimated cost per attempt × average attempts per task
For a fair comparison, use the same traffic mix, prompt versions, retrieval settings, and tool-call behavior for both models. If the candidate changes the number of tokens or calls, record that as part of the result rather than comparing rates alone.
3. Score outcomes, not just responses
Build a test set from real request categories: short answers, long context, ambiguous inputs, malformed inputs, edge cases, tool calls, and retrieval-heavy tasks. Score each response against acceptance criteria such as factual support, required fields, instruction following, citation behavior, safety handling, and business-rule compliance.
For prompt testing guidance, see the prompt testing and evaluation framework. If the application uses retrieval, test the complete retrieval-augmented generation path rather than evaluating the model in isolation; the RAG tutorial provides a useful workflow context.
Inputs and assumptions
Create a migration worksheet before selecting a replacement. Every value should have a source, a measurement window, or an explicit assumption.
| Input | How to capture it | Why it matters |
|---|---|---|
| Traffic volume | Requests per day or month, separated by use case | Determines capacity, spend, and rate-limit exposure |
| Token profile | Median and high-percentile input and output tokens | Reveals context and pricing risk hidden by averages |
| Quality threshold | Pass/fail rubric for each task category | Prevents a low-cost but unacceptable migration |
| Latency target | Time-to-first-token and complete-response targets | Separates interactive workloads from asynchronous jobs |
| Reliability target | Allowed error, timeout, and retry rates | Shows whether fallback capacity is necessary |
| Compatibility constraints | Required schema, tools, modalities, context, and streaming | Eliminates candidates that cannot support the product |
| Commercial inputs | Current provider pricing, limits, discounts, and contract terms | Allows the estimate to be refreshed when rates change |
Keep assumptions visible. For example, state whether token counts include system instructions, whether retries are counted, whether cached inputs receive separate treatment, and whether tool execution costs are included. Do not assume that similarly named parameters have identical meanings across providers. Temperature, sampling controls, stop behavior, seed handling, response limits, and reasoning-related settings may differ or may not be supported.
Use an adapter with a normalized internal response object. Preserve provider-specific metadata separately for debugging, but expose consistent fields to the application: text, structured data, tool calls, finish reason, usage, request identifier, and error category. This reduces the number of code paths that must change during a migration.
Worked examples
Example 1: Cost comparison with hypothetical inputs
Suppose an application handles 100,000 monthly tasks. Its current model averages 2,000 input tokens and 500 output tokens per attempt, with 1.10 attempts per successful task. These figures are illustrative, not current provider data.
For a candidate model, enter its published input and output rates into the worksheet. Monthly input tokens are:
100,000 × 2,000 = 200,000,000 input tokens
Monthly output tokens are:
100,000 × 500 × 1.10 = 55,000,000 output tokens
Apply the candidate’s billing unit and rates to those totals, then add any applicable request, tool, storage, or retrieval charges. Repeat the calculation using measured candidate-model token counts. If the candidate produces longer answers or causes more retries, those changes belong in the estimate.
Example 2: Output-parity test template
Run each test case through the current and candidate models with the same input, prompt version, retrieved context, tool definitions, and decoding settings where compatible.
Test ID:
Use case:
Input class: normal | edge | malformed | long-context | tool-call
Required behavior:
Required fields or schema:
Allowed variation:
Current result: pass | fail
Candidate result: pass | fail
Current tokens / latency:
Candidate tokens / latency:
Safety or policy notes:
Reviewer decision:
Follow-up action:
Compare invariants rather than raw strings. A summary may use different wording while still passing; a JSON response with different key ordering may be equivalent; a missing required field is not. For inconsistent or off-format results, use the prompt debugging checklist before concluding that the model itself is unsuitable.
Example 3: Fallback design
Define fallback behavior by failure class. A transient timeout may be retried with bounded backoff; a schema-validation failure may trigger a repair path or a second model; an unsupported tool call should be treated as a compatibility error rather than retried indefinitely. Log the original provider, candidate provider, model identifier, attempt count, and final outcome.
For agentic applications, test the complete sequence of planning, tool selection, argument validation, execution, and final response. The function calling and tool-use guide and AI agent workflow patterns can help structure those checks.
When to recalculate
Treat a model migration estimate as a living operational document. Recalculate before launch, after the first meaningful production sample, and whenever an underlying input changes. At minimum, revisit it in these situations:
- A provider changes pricing, billing units, context limits, quotas, or rate limits.
- A model version, endpoint, SDK, tokenizer, or default parameter changes.
- Prompt templates, retrieval chunking, tool definitions, or output schemas change.
- Traffic mix, average response length, retry rate, or concurrency changes.
- Latency, error rates, quality scores, or user complaints move outside the baseline range.
- You introduce a new fallback, batch path, cache, routing rule, or agent workflow.
- A provider announces a deprecation or changes a feature your adapter depends on.
Use this pre-launch checklist:
- Freeze the evaluation dataset and record its version.
- Confirm current provider pricing, limits, model capabilities, and SDK behavior from the relevant documentation.
- Run output-parity, schema, tool-call, long-context, failure, and security tests.
- Recalculate cost per request and cost per successful task using observed candidate usage.
- Verify dashboards include provider, model, token usage, latency, retries, and error categories.
- Release behind a feature flag or controlled traffic split.
- Set explicit rollback thresholds for quality, latency, cost, and reliability.
- Document the selected model, assumptions, test results, and next review date.
Finally, review prompt and tool inputs for security issues during every migration. A new model may interpret untrusted retrieved text or user instructions differently, so include injection and data-handling tests; the prompt injection prevention checklist is a practical companion. A disciplined worksheet, adapter, evaluation set, and rollback path turn switching AI models from a risky rewrite into a measurable maintenance process.