ai newsDi., 1. Dez.

Model Routing: Cut Your LLM Costs 40-60% Without Dropping Quality

Most apps pay strong-model prices for tasks a cheap model does perfectly. Here's how to route by task type instead. If you're sending every request to the same flagship model, you're probably overpaying by half. The trick isn't picking a cheaper model — it's noticing that your workload is not homog

dev.toSonntag 10:57 · 29.11.2 Min. Lesezeit
Bild: dev.to

Most apps pay strong-model prices for tasks a cheap model does perfectly. Here's how to route by task type instead.

If you're sending every request to the same flagship model, you're probably overpaying by half. The trick isn't picking a cheaper model — it's noticing that your workload is not homogeneous.

Classification, extraction, formatting, and routing decisions are easy. Reasoning, code generation, and nuanced writing are hard. Yet most pipelines hit the same model for both.

incoming task │ ├─ classifier (fast model, ~$0.10/M tokens) │ decides: SIMPLE / MEDIUM / HARD │ ├─ SIMPLE → fast model (trimming summaries, tags, extraction) ├─ MEDIUM → mid model (standard Q&A, short rewrites) └─ HARD → flagship model (multi-step reasoning, code, long context) Enter fullscreen mode Exit fullscreen mode A classifier call costs a fraction of a cent and pays for itself the moment it sends one "summarize this tag" request to a fast model instead of a flagship.

Not "model X is smart" — rules you can implement in an afternoon:

The last row matters: routing and failover are the same subsystem. If you're tracking endpoint health anyway (latency, success rate over a rolling window), the router should simply skip endpoints that are currently degraded. One health probe, two benefits.

TIERS = [ "fast", "mid", "flagship" ] def complete ( task, hints ): tier = classify ( task ) # fast model call for attempt in range ( 3 ): ep = pick_endpoint ( tier, exclude = dead_endpoints ( ) ) try: return call ( ep, task, timeout = 20 ) except RateLimited: backoff ( attempt ) # 1s, 2s, 4s except ServerError: tier = TIERS [ min ( TIERS. index ( tier ) + 1, 2 ) ] # escalate raise AllTiersFailed Enter fullscreen mode Exit fullscreen mode Two ideas in one loop:

A typical mixed workload (my own usage, a week):

Flat flagship pricing: 100% × flagship_rate. Routed: 70% × fast_rate + 25% × mid_rate + 5% × flagship_rate. With typical price gaps of 10–20× between tiers, the blended rate lands at 40–60% of flat — and quality on the 5% that matters is untouched, because those calls still go to the flagship.

Every routed run should append a JSONL line: task id, tier decision, endpoint chosen, attempts, latency, tokens. When something looks wrong weeks later ("why did this batch cost 3×?"), the trace answers it in minutes. Without it, you're guessing.

This is the second half of a system I build for clients: health probe → router → failover, wired to whatever endpoints you already have. If your stack is n8n, Node.js, or Python, the whole thing is a week of my evenings — or an afternoon of yours with the patterns above.

Next post: agent workflows that survive flaky providers — JSONL traces, replayable runs, and why "just retry" isn't error handling.

Quelle: dev.to (dev.to). Original öffnen