MLog

A bilingual blog crafted for our own voice

Back to posts
后端#AI#后端#模型路由#工程化

Model Routing Is Just a Backend Problem

Published: Jul 12, 2026Reading time: 6 min

When your application needs to talk to half a dozen LLM APIs simultaneously, model routing stops being an AI problem and becomes a proper backend engineering one—auth, rate limiting, fallbacks, canary releases, and billing. All familiar territory.

I've been working on a side project that needs to call multiple LLM APIs. It started simple enough—just wrap an HTTP call. Then the requirements piled up: cheap models for simple queries, powerful ones for complex reasoning, automatic failover during peak traffic, different clouds for different regions. By the third if-else block, I knew I shouldn't be hand-rolling this.

A few things happened recently that, taken together, paint a clear picture.

On July 1, GitHub Copilot CLI shipped auto model selection—it routes each task to the optimal model based on task type, real-time availability, and cost. On July 10, OpenAI dropped GPT-5.6, claiming it beats Claude across the board, but the real headline was pricing: as low as 1/16 of competitors. A bit earlier, Tencent released Hunyuan Hy3, a 295B MoE model with only 21B active parameters, pushing inference costs down to a fraction of flagship models.

The pattern is obvious: models are no longer scarce. Choice is abundant. But "which one do I use?" has become its own kind of complexity.

More Models, More Problems

A year ago, the playbook was straightforward: pick the strongest model and call it a day. That doesn't work anymore. In a real production system, you're likely dealing with scenarios like these:

  • Simple Q&A goes to a cheap, fast model; complex code tasks go to a heavy lifter
  • Sensitive data stays on private deployments; routine requests hit public clouds
  • Overseas users route to overseas models; domestic users stay local
  • When a model hits rate limits or goes down, traffic automatically switches to a fallback

And that's before you even get to enterprise needs: token usage monitoring, per-team billing, compliance auditing.

If you have one model, one HTTP client is fine. Once you have five models across three clouds in two regions, you're no longer "calling an API." You're building a gateway. And building gateways is what backend engineers have been doing for decades.

LiteLLM: A Gateway Worth Looking At

On the open-source side, LiteLLM has become the de facto AI Gateway. Over 240 million Docker pulls, a billion requests served, more than a thousand contributors, and Netflix is using it in production.

The core idea is dead simple: normalize 100+ LLM providers into one OpenAI-compatible interface. Whether you're calling GPT, Claude, Gemini, or a domestic model, your code just calls litellm.completion(). Streaming, function calling, embeddings—all supported with minimal changes to existing code.

What I find more interesting is the Proxy Server mode. Run it as a self-hosted gateway, and you get far more than API translation:

  • Load balancing: Distribute traffic across model instances by RPM/TPM
  • Failover: Automatic fallback when the primary model goes down—transparent to users
  • Budgeting and rate limiting: Set spending caps per key, user, or team
  • Spend tracking: Automatic per-dimension token and cost accounting
  • Guardrails: Content filtering on both request and response

Strip away the AI branding, and this is just microservice gateway patterns applied to LLMs. Auth, rate limiting, routing, circuit breaking, monitoring—every item on that list is something backend teams have been doing for fifteen years. The models are new, but the operational problems are old.

GitHub Copilot's Bet: Don't Make Users Choose

GitHub took a more radical approach. Copilot's auto model selection removes the "pick a model" step entirely. Users only see an "Auto" option. Behind the scenes, the system evaluates the task—how much reasoning it needs, code generation complexity, bug diagnosis difficulty, tool orchestration requirements—and matches it against real-time model health and availability data to route accordingly.

The routing also respects natural caching boundaries, minimizing unnecessary model switches that would invalidate caches and drive up costs.

I really like this design philosophy. Users don't need to know whether the request hit GPT-5.6 or Claude or Gemini. They just need to know the job gets done well—same as how nobody cares which index or retrieval pipeline a search engine used. You just want the result.

But I suspect most teams can't copy this playbook wholesale. GitHub can do it because they're a model consumer, not a model builder. They have no allegiance to any particular model and can hop between providers freely. Many companies, especially in certain markets, train their own models or have deep partnerships with specific cloud vendors. For them, model selection isn't a purely technical decision.

What Makes This Actually Hard

Here's my take: model routing isn't hard because of the algorithm. You don't need a neural network to pick a model for you. It's hard because it demands solid engineering infrastructure.

First, protocol consistency. Most provider APIs look like OpenAI's, but the devil is in the details. One doesn't support a certain streaming parameter. Another has a slightly different function calling format. Token usage fields have different names. A good chunk of LiteLLM's thousand-plus contributors have been filling these exact gaps.

Second, observability. When you're running five models concurrently, you need to know which model handled each request, how many tokens it consumed, the latency, the failure reason, and whether any sensitive data rules were triggered. This data isn't just for ops—it's for accounting. You'll likely need to attribute model costs by team, project, or feature module.

Third, canary releases. Models update fast. Before rolling out a new version, you want to send 5% of traffic to it first and observe. Sound familiar? That's exactly the canary deployment pattern from microservices. Model switching shouldn't require code changes and redeploys—it should happen through dynamic configuration.

What I'd Recommend

If you're running a single model with modest traffic, don't jump to a gateway. An HTTP client with two or three if-else branches is fine. Over-engineering kills early-stage projects.

But if you're already juggling multiple models or your traffic is growing fast, I'd suggest pulling model routing into its own layer sooner rather than later. It doesn't have to be LiteLLM—a lightweight custom implementation works too. The key is separating "which model do I call?" from your business logic.

At minimum, this layer should answer three questions:

  1. Which model should handle this request?
  2. If the primary model is unavailable, what's the fallback?
  3. How many tokens and how much did this call cost?

Once you can answer those three questions cleanly, your model integration graduates from "it works" to "it's operable." Rate limiting, canary releases, budget controls—those all grow naturally on top of that foundation.

One last thing: don't let the term "AI Gateway" intimidate you. It's not some arcane piece of AI infrastructure. It's a reverse proxy with business routing logic. Nginx, Kong, Envoy—same patterns, same problems. The models are cutting-edge, but the engineering is decidedly not.