Prompt
I need to swap model providers without changing my app code
Latest observation
Oct 9, 2026
OpenAI APIWeb search: off
You can do that by putting a provider-agnostic wrapper in front of your app and switching providers behind a stable interface.
Best approach
Use an abstraction layer so your app talks to one internal API, not directly to OpenAI / Anthropic / etc.
Options
-
Use an LLM gateway
- Examples: LiteLLM, OpenRouter, Vercel AI Gateway, Portkey
- Your app keeps the same request shape while the gateway routes to different providers.
-
Create your own adapter
- Define a small internal interface like:
chat(messages, temperature, max_tokens, ...)embeddings(texts)moderation(input)
- Implement one adapter per provider.
- Define a small internal interface like:
-
Use SDKs with compatible abstractions
- Some frameworks normalize providers:
- LangChain
- LlamaIndex
- Vercel AI SDK
- Good if your app already uses them.
- Some frameworks normalize providers:
What to standardize
To avoid app-code changes later, keep these stable:
- message format
- streaming behavior
- tool/function calling schema
- token limits
- error handling
- retry/timeouts
- model aliasing, e.g.
fast-chat,best-chat,cheap-chat
Recommended pattern
Use an internal config mapping:
FAST_CHAT -> gpt-4o-miniorclaude-haikuBEST_CHAT -> gpt-4.1orclaude-sonnetEMBEDDINGS -> text-embedding-3-large
Then switching providers is just config, not code.
Example architecture
Your app → your internal client → gateway/adapter → provider
This lets you:
- change providers
- A/B test models
- fall back on outages
- route by cost/latency
- keep the app unchanged
If you want the easiest path
- If you want minimal code changes: use LiteLLM or OpenRouter
- If you want full control: write your own thin adapter
- If you want framework support: use Vercel AI SDK or LangChain
If you want, I can give you:
- a drop-in adapter design,
- a LiteLLM setup, or
- a provider-neutral interface example in your language.