Moving an LLM application to another provider or model family is less like changing a URL and more like replacing a dependency with different interfaces, limits, and behavior. This guide gives you a repeatable migration method: inventory the current integration, estimate engineering and usage costs, isolate provider-specific code, test prompts and outputs, and release the new model without losing observability or safety controls.
Overview
An LLM API migration may be triggered by a model retirement, a pricing change, a reliability issue, a new capability, or the need for a lower-cost fallback. The visible request may look simple—send messages and receive text—but production applications often depend on much more:
- Authentication, regional endpoints, and organization or project settings
- Message roles, content parts, multimodal inputs, and conversation state
- Tool or function calling, schema formats, and tool-result messages
- Streaming events and partial-response handling
- Structured output behavior and JSON validation
- Context limits, rate limits, timeouts, retries, and error codes
- Safety settings, logging rules, data retention options, and usage reporting
An “OpenAI-compatible” endpoint can reduce the amount of code you change, but compatibility should not be treated as equivalence. Parameter names may match while tokenization, instruction following, tool selection, refusal behavior, latency, and structured-output reliability differ. Keep an adapter layer between your application and the provider so these differences remain contained.
The migration has two separate estimates. First, calculate the one-time work required to change and validate the integration. Second, calculate the recurring cost of running the workload on the candidate model. A cheaper token rate does not automatically produce a cheaper system if the model requires longer prompts, more retries, extra validation, or human review.
For related planning, see this LLM API pricing comparison and cost-per-task guide and the LLM model deprecation guide.
How to estimate
Start with a migration worksheet rather than a provider comparison based only on advertised features. Record the current implementation, the target implementation, and the evidence needed to approve the change.
1. Inventory the existing contract
List every place where your application calls the model. For each call, record the model identifier, input types, average and maximum prompt size, expected output size, temperature or equivalent controls, tools, response schema, streaming mode, timeout, retry policy, and fallback behavior. Include batch jobs, evaluation scripts, staging environments, and internal tools; overlooked callers frequently delay a migration.
2. Classify provider-specific features
Divide the integration into portable and provider-specific parts. A portable core might contain your business prompt, input validation, output parser, and application-level tracing. Provider-specific code might contain SDK initialization, message serialization, tool definitions, stream-event parsing, usage extraction, and error mapping.
Use a small interface such as:
generate(request) -> response
stream(request) -> events
count_usage(response) -> usage
classify_error(error) -> retryable | permanent | unknown
The exact interface is up to your application. The goal is to prevent business logic from depending directly on one vendor’s message objects or exception classes.
3. Calculate recurring usage cost
Use the provider’s current pricing documentation for the target model rather than copying figures from an old comparison. A basic estimate is:
monthly cost = requests per month × cost per request
For token-priced models, expand the calculation:
cost per request =
(input tokens ÷ billing unit × input rate) +
(output tokens ÷ billing unit × output rate) +
tool, search, image, or other metered charges
Estimate at least three traffic levels—expected, high, and peak—and include retries. If a request has a retry probability of r, a simple expected-request adjustment is requests × (1 + r). This is only an approximation; backoff behavior and repeated failures can make peak consumption much higher.
4. Add migration effort and operational risk
Estimate hours for code changes, prompt adaptation, test creation, security review, deployment, monitoring, and rollback preparation. Then score the candidate against acceptance criteria such as task quality, valid structured responses, tool-call accuracy, latency, error rate, and safety review outcomes. A model that passes a short demo but fails production-shaped tests is not a successful migration.
Inputs and assumptions
Keep the following inputs in a versioned worksheet. They make the estimate reproducible when traffic, pricing, or model behavior changes.
| Input | What to record | Why it matters |
|---|---|---|
| Request volume | Requests per day or month, including batch traffic | Determines baseline usage and capacity needs |
| Token distribution | Typical, high-percentile, and maximum input and output tokens | Average tokens can conceal expensive long-tail requests |
| Retry rate | Retries caused by timeouts, rate limits, and transient failures | Raises cost and can amplify traffic during incidents |
| Feature mix | Text, images, tools, retrieval, caching, or batch processing | Additional features may use separate limits or billing units |
| Quality threshold | Required score or pass rate for real application tasks | Prevents a low price from outweighing unacceptable output quality |
| Latency target | Time to first token and complete response time | Streaming and model choice affect user experience differently |
| Reliability target | Accepted timeout, error, and fallback rates | Supports a practical go/no-go decision |
Do not assume that identical prompts produce identical results across model families. Check instruction hierarchy, system-message handling, context-window limits, stop conditions, tool schemas, JSON enforcement, and reasoning or verbosity controls. If your application uses retrieval, preserve the retrieved text and citations while changing only the model layer where possible. For prompt changes, create a before-and-after test set and review failures manually as well as with automated checks.
For a production test strategy, use the LLM prompt regression testing guide. If your application depends on retrieval quality, also separate embedding and reranking changes from generation changes; the embedding model comparison guide provides a useful planning reference.
Worked examples
Example 1: Estimating monthly usage
Assume an application handles 50,000 requests per month. For a planning exercise, suppose each request averages 2,000 input tokens and 500 output tokens. The target provider’s published pricing should supply the input and output rates; do not substitute an outdated figure.
The monthly token volumes are:
- Input: 50,000 × 2,000 = 100,000,000 tokens
- Output: 50,000 × 500 = 25,000,000 tokens
If the team expects a 4% retry rate, use approximately 52,000 billable attempts for a first estimate, then model a separate peak scenario. Plug those volumes into the target provider’s current rates. Repeat the calculation for the existing model and at least one fallback. If the target has a lower token rate but produces longer outputs, update the output-token assumption and recalculate rather than relying on the advertised discount.
Example 2: Comparing migration effort
Suppose the current application uses plain text generation, streaming, structured JSON, and one tool. A reasonable worksheet might separate the work into authentication and client setup, message conversion, stream parsing, tool-call conversion, schema validation, prompt adaptation, regression testing, deployment, and rollback. Assign an estimate to each task and mark unknowns explicitly.
For example, if message conversion and stream parsing are small changes but tool calling and structured output require substantial validation, the migration should not be approved solely because the basic text endpoint responds successfully. Require representative tests for malformed JSON, missing tool arguments, interrupted streams, rate-limit responses, and provider-side validation errors.
Example 3: Measuring the decision, not just the price
Build a test set from real, anonymized requests. Record whether each response meets the task requirement, whether the schema validates, whether citations or extracted fields are correct, and how long the request takes. Compare the current and target models under the same application-level criteria. A weighted decision can include quality, cost, latency, reliability, privacy requirements, and engineering effort. Document the weights so another engineer can reproduce the recommendation.
For broader evaluation design, see how to benchmark LLMs for a real-world use case.
When to recalculate
Recalculate the migration estimate whenever a provider changes pricing, model availability, context limits, rate limits, tool-calling behavior, structured-output support, or deprecation dates. Also revisit it when your traffic mix changes, prompts become longer, retrieval adds more context, or retries increase after a production release.
A quarterly review is a practical baseline for a live application, with an immediate review after any provider announcement that affects your model or API. Keep a dated record of model identifiers, SDK versions, endpoint settings, pricing assumptions, benchmark results, and known limitations. This prevents a future team from treating an old estimate as current.
Before switching traffic, complete this checklist:
- Confirm the target model, endpoint, SDK version, pricing unit, and deprecation terms from current provider documentation.
- Implement an adapter for authentication, messages, streaming, tools, structured responses, usage, and errors.
- Run representative quality, latency, cost, and failure-mode tests.
- Deploy behind a feature flag or controlled traffic split with dashboards for tokens, spend, errors, latency, and fallback use.
- Set explicit rollback conditions and retain the old integration until the migration is stable.
- Record the final assumptions and schedule the next review.
The safest LLM API migration is an ordinary, measurable software change: isolate dependencies, test the behavior that matters to users, and recalculate the economics whenever the inputs move.