What it takes to switch AI providers

Why changing models involves more than an API URL, and where fallback, privacy, and testing come in

At PT EbyB Global Marketplace, I worked on AI integrations using OpenAI, DeepSeek, and self-hosted Ollama, including failover between providers. AI operating costs fell by approximately 95% across the broader omnichannel and AI infrastructure work, not as a result of one model or service.

Changing providers involves more than swapping an API URL. Models differ in what they support, how they fail, and where their data goes. The examples here are general guidance, not a description of private deployments.

Separate the application contract from the provider request

Start by describing what the application needs: perhaps a short text response, a structured classification, or a tool-capable conversation. Keep provider model identifiers, authentication details, and response parsing behind an adapter boundary.

A useful application-level request might carry the task, input, output requirements, deadline, and data-handling constraints. The adapter translates those requirements into a provider request. It also translates the response into an application result with usage information and a meaningful completion status.

Do not normalize away important differences. A response stopped by an output limit is not equivalent to a completed response. A refusal is not merely an empty string. Preserve enough information for the caller to decide what happens next.

The goal is a stable boundary, not a universal schema that pretends every provider behaves identically.

Represent capabilities explicitly

Two services can accept similar chat-shaped payloads while supporting different behavior. Structured output guarantees, tool calling, image input, streaming events, context limits, and usage reporting can differ across providers and model versions.

Keep an explicit capability description for each supported deployment. A task requiring schema-constrained output should only route to candidates that meet that requirement, or use a documented validation-and-repair strategy appropriate to the task. Prompting a model to "return JSON" is not the same guarantee as constrained generation.

Avoid silently dropping unsupported parameters. If the application requires a capability, reject an incompatible route before making the request. If a feature is optional, define the degraded behavior visibly.

Provider independence sometimes means supporting several well-defined task interfaces rather than one lowest-common-denominator interface. Embeddings, text generation, and tool execution do not need to share a single abstraction merely because all involve models.

Classify failures before deciding to switch

A generic "provider failed" error is insufficient for routing. Separate failures that suggest different actions:

  • Invalid request or unsupported capability: Correct the request or route selection; repeating it unchanged is unlikely to help.
  • Authentication or account configuration: Alert the operator. Another route is usable only if policy explicitly permits it.
  • Rate limit or temporary unavailability: Consider a bounded retry or eligible alternate route within the deadline.
  • Timeout or uncertain completion: Account for the possibility that the original request continued processing.
  • Safety refusal or invalid output: Apply task policy and validation, not an automatic search for a less restrictive response.

Track the original failure even when an alternate attempt succeeds. Otherwise a healthy-looking success rate can hide a broken primary route.

Make fallback an explicit product policy

A retry sends another attempt, often to the same provider. A fallback changes the selected route or model after a failure or policy decision. They have different quality, privacy, and billing consequences.

Define which failures permit fallback, which destinations are eligible, how many attempts are allowed, and how the total deadline is shared. An alternate provider must satisfy the original data-handling constraints. Availability does not justify silently moving sensitive inputs elsewhere.

Automatic switching is not always desirable. A single-shot operation that reports failure clearly can be the right contract when predictability or caller-controlled retries matter more than hidden recovery. Provider flexibility and automatic failover are separate capabilities.

Streaming makes the boundary harder: after text reaches the client, switching models can duplicate content or break the response. Decide whether fallback is allowed only before the first emitted token. For tool-capable systems, retries must not blindly repeat external side effects. Use application-level idempotency and explicit tool-execution state where needed.

Track each request and provider attempt

Record one logical operation with separate records for its provider attempts. Useful fields include task category, provider and model version, latency, completion status, retry reason, fallback reason, and available usage data.

Measure the caller's end-to-end experience as well as individual attempt duration. A fast successful fallback can still produce a slow overall request after a long initial timeout. Distinguish cancellation from provider rejection and incomplete generation from valid completion.

Keep observability compatible with privacy requirements. Prompts and responses can contain sensitive information; logging them by default creates another data store to secure and govern. Redacted metadata and carefully controlled samples may be sufficient for many operational questions.

Usage accounting also needs uncertainty. Provider reports may omit fields or use different definitions. Mark estimates as estimates instead of treating all token and cost figures as directly interchangeable.

Evaluate replacements before routing real work

An adapter test can prove request translation without proving that a replacement model is suitable. Evaluate representative tasks, including ambiguous inputs, long conversations, malformed outputs, refusals, and tool-call arguments.

Use task-specific acceptance criteria. A classification workflow may prioritize correct labels and valid structure; a support draft may also need factual grounding and appropriate escalation. Syntactically valid output is not automatically useful output.

Version the evaluation set and the model configuration so changes can be compared meaningfully. Include human review for judgments that automated checks cannot reliably establish. Test the adapter's failure behavior separately from model quality, using controlled simulations where possible.

Re-evaluate when model versions, prompts, context construction, or routing policies change. A familiar provider name does not guarantee unchanged behavior.

Optimize the whole operation, not the listed token price

A cheaper request can become expensive if it needs repeated repairs, longer prompts, or manual correction. Self-hosted Ollama shifts costs toward hardware, capacity planning, deployment, and operations; it does not eliminate them. Data locality also depends on surrounding logging and network paths, not just the model host.

Compare candidates against quality, latency, privacy, reliability, and total operating cost for the actual task. Routing a simpler task to a smaller model can be sensible, but only after its output meets the relevant acceptance criteria.

Keep provider calls easy to replace without hiding their differences. That leaves room to change models while keeping the application’s requirements intact.

Have a question or a different take?