April 8, 20263 min readGuide

How to switch LLM providers without rewriting your code

Picking a single LLM provider and hard-wiring your app to it feels efficient — until the day you need to move. Maybe a new model is cheaper, maybe latency spiked, maybe your favorite frontier model got deprecated. If your codebase is tangled with one vendor's SDK, "trying another model" turns into a migration project.

The good news: you don't have to live like that. With an OpenAI-compatible gateway, switching providers becomes a one-line change.

Why migrations hurt

Each official SDK has its own client object, auth scheme, request shape, and response format. Anthropic's messages API, Google's generateContent, and OpenAI's chat/completions all disagree on field names, streaming formats, and how tool calls are encoded. Wire your business logic directly to one of them and you've coupled your code to that vendor forever.

The fix is an old idea: program against a stable interface, not a specific implementation.

Use the OpenAI-compatible interface as your stable contract

The OpenAI chat/completions shape has become the de facto standard. Most clients, frameworks, and tools already speak it. If you route every request through one endpoint that accepts that shape, your application code never needs to know which provider is behind it.

That's exactly what AnyModel does. One base URL, one API key, and every model — GPT, Claude, Gemini, DeepSeek, GLM, Kimi, Qwen, Grok — is reachable through the same request format.

Switching models is the entire migration:

curl https://anymodel.org/v1/chat/completions \
  -H "Authorization: Bearer $ANYMODEL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4.5",
    "messages": [{"role": "user", "content": "Summarize this in one line."}]
  }'

Want to compare it against another provider? Change "model" to gpt-5, gemini-2.5-pro, or deepseek-v3. Nothing else moves — not the URL, not the auth header, not the parsing code.

Point your existing SDK at the gateway

You don't even need to drop your current library. The official OpenAI SDKs accept a custom base_url, so you keep the code you already wrote:

from openai import OpenAI

client = OpenAI(
    base_url="https://anymodel.org/v1",
    api_key="YOUR_ANYMODEL_KEY",
)

resp = client.chat.completions.create(
    model="kimi-k2",          # swap this string anytime
    messages=[{"role": "user", "content": "Hello"}],
)

The model string becomes your single point of control. Put it in an environment variable and you can switch providers at deploy time without touching source at all.

Wiring up coding tools

If you work in a terminal coding agent, setup is a one-liner. For codex, claude, opencode, and hermes:

bash <(curl -fsSL "https://anymodel.org/i?tool=codex") <YOUR_API_KEY>

Use tool=claude for Claude Code. For editors and clients without that installer — Cursor, Windsurf, Zed, Cline, Aider, Continue, or Gemini CLI — just plug in the OpenAI-compatible settings manually: set the base URL to https://anymodel.org/v1 and paste your key. Same contract, different UI.

A quick checklist for provider-agnostic code

Do this Instead of this
Read the model id from config/env Hard-coding it in source
Route through one OpenAI-compatible base URL Importing three vendor SDKs
Keep prompts free of vendor-specific syntax Relying on one provider's quirks
Test the same prompt across models Assuming one model is always best

With that in place, "evaluate a new model" stops being a sprint and becomes a one-character edit. Our side-by-side comparison page makes it easy to see how candidates differ before you commit.

Try before you spend

You get 1,000,000 free tokens on signup — no credit card — and a total of 6,000,000 if you link Telegram. After that it's pay-per-token: no subscription, no minimums. That's enough room to benchmark several providers against your real workload.

If your prompts are sensitive, Ghost Mode offers opt-in zero-retention keys: we don't store prompts or responses, only a token counter. (The underlying model provider still receives the prompt, so this isn't absolute privacy — but nothing lingers on our side.)

For more practical walkthroughs, browse the blog.

Stop coupling your codebase to a single vendor. Create your free account, point your code at one endpoint, and switch models with a single string.

Read next