DEV Community

Cover image for Model routing: who picks the AI that answers you?
System Design Simple
System Design Simple

Posted on Originally published at systemdesignsimple.com

Model routing: who picks the AI that answers you?

When you send a message to an AI app, a gateway may decide which model answers before any model is called. A greeting can go to a small, cheap model and a maths problem to a big, expensive one. That choice is model routing, and it is the same job a layer 7 load balancer does with HTTP: read the request, then pick an upstream. The difference is the backends are not equal. In our assumed price table the big model costs 20 to 25 times more per token.

We tested the simplest router: a keyword rule in plain JavaScript, run on 60 everyday prompts we labelled by hand, 42 easy and 18 hard. No model was called, so this is a routing simulation, not a benchmark.

The rule scores each message. A long message over 280 characters adds 1. A maths expression or word adds 2. A code fence or code word adds 2. A reasoning word such as "prove" or "step by step" adds 2. A score of 2 or more goes to the big model, anything less goes small.

The results: 43 of 60 prompts went to the small model and 17 to the big one. The rule agreed with our hand labels on 55 of 60, or 91.7%. That is label agreement, not answer quality. Each decision took about 0.31 microseconds, measured over 120,000 decisions.

The 5 misses are the interesting part. Two easy prompts went big: "What is 2 + 2?" and a long thank-you note that says "step by step". Three hard prompts went small: the bat-and-ball riddle, a short logic puzzle, and counting the letter r. The three misses share a shape: short, plain words, no symbols, and a trap inside. Keyword rules are weakest exactly where questions look simple and are not.

The cost model uses assumed prices: small at 0.15/0.60 USD and big at 3/15 USD per million input/output tokens, with reply lengths assumed at 60 tokens for easy prompts and 500 for hard ones. Always big costs $2.923 per 1,000 requests. Routed, it costs $1.966, which is 32.8% less. But when we rerun the same model with the 3 hard misses sent big, the saving drops to 20.3%.

A checker can catch some of it. FrugalGPT-style cascades ask the cheap model first, score the answer, and only escalate when the score is low. Our lab only models that idea: if the small model failed 60% of hard prompts and a checker caught 80% of those failures, the expected wrong answers per 1,000 requests would fall from 30 to 6 and the saving would shrink to 26.5%.

Our take: a rule that costs 0.31 microseconds is cheap enough to run on every request, and on our prompts it was right most of the time. More than a third of the modelled saving came from three hard questions that looked easy. If you add routing, log every request that went small, sample those answers, and measure misses by kind before trusting the bill.

Read the full article on System Design Simple: https://systemdesignsimple.com/who-decides-which-ai-answers-your-message/

Top comments (0)