Cost Tutorials
How to Route LLM Requests by Workload
To route LLM requests by workload, filter candidate models by context size and required capabilities, then choose a route that fits the task’s quality bar, latency deadline, and cost budget. Use rules when the application knows the task, a learned router when model choice depends on the prompt, or a cascade when you can check an answer before escalating. Compare each policy with a fixed model using total cost per accepted answer, acceptance rate, and end-to-end latency.
Step 1. Define what each workload needs
Start with the product action the request supports. Record what counts as an accepted result, how long the user can wait, what the model must read, and how much the application can spend on the task. Use these requirements to decide which constraints make a model ineligible and which help rank the remaining candidates. OpenRouter documents a similar sequence for its Auto Router: it filters the candidate pool, then weighs the request against pricing and performance signals. OpenRouter Auto Router
| Constraint | What to specify | How to apply it |
|---|---|---|
| Quality | The rubric or validation check that defines an accepted answer | Evaluate eligible models against that check on representative tasks. |
| Latency | The time budget for the full user-visible operation | Budget for the route decision, model calls, answer checks, and any fallback. For streaming, track time to first token alongside time to a usable result. Latency versus throughput |
| Context size | The assembled input and the output space the task needs | Check that the request fits before dispatch. Include instructions, conversation history, and any attached excerpts in your estimate. LLM context windows |
| Cost | The spend limit for the entire task | Account for any additional call the policy can trigger and check the remaining budget before escalating. How to calculate LLM API cost |
For an illustrative rule, send extraction requests to a model that has passed your field-level checks and can handle the assembled input. Send an evidence-heavy review to a model tested against that review rubric. If a request exceeds every eligible model’s context budget, return a clear error or offer an explicitly supported way to reduce the input.
Step 2. Choose how to make the routing decision
Start with rules for known tasks
When the application already knows the operation, use that signal to route the request. Map the feature or explicit task type to an ordered set of approved candidates. Check context and capability requirements before choosing the first eligible model. Record which rule matched and specify what happens when none matches. A rules-only policy gives you a baseline for evaluating learned routing. RouteLLM compared its routers against a random-routing baseline; for your application, the rules-only policy plays that role. LMSYS RouteLLM write-up
Test a learned router when model choice depends on the prompt
A learned router can choose between candidate models before generation. RouteLLM trains routers with preference data about which model gave the better response to a prompt. RouteLLM paper For a workload you own, test the decision threshold on held-out tasks and measure the outcome at the threshold you plan to deploy.
In its July 2024 write-up, LMSYS reported that an augmented matrix-factorization router reached 95% of GPT-4 performance on MT Bench while sending 14% of calls to the stronger model in its GPT-4 Turbo and Mixtral 8x7B evaluation. The same write-up reported near-random results on MMLU when the routers trained only on Chatbot Arena data. These results describe those benchmark setups; test separately on your workload. LMSYS RouteLLM write-up
For a managed example, OpenRouter’s Auto Router documentation (accessed November 2026) describes allowed_models as a restriction on which models the router may choose and cost_tier as a way to select a routing policy. Use an explicit allowlist if your application approves models individually, and evaluate which models the configured policy selects. OpenRouter Auto Router
Use a cascade when you can check the answer
In a quality cascade, generate an answer, check whether it meets the acceptance criteria, and call the next eligible model if it fails and the budget permits. FrugalGPT, introduced in 2023, is a research example of learning which combinations of models to use for different queries. FrugalGPT paper
For an illustrative extraction cascade, check required fields and verify that returned values appear in the input. Give the next model the same acceptance criteria. Define a terminal outcome for cases where the result still fails or the task runs out of time. Measure how often the check accepts answers that your review rubric would reject; those answers can leave the cascade marked as accepted.
Step 3. Specify what each fallback can change
| Fallback path | Trigger to define | What the next attempt changes |
|---|---|---|
| Provider fallback | An eligible endpoint fails or cannot serve the request | Try another eligible provider for the same model. OpenRouter says a routed request goes through its normal provider routing, where provider health, latency, price, and your provider preferences apply. OpenRouter Auto Router |
| Model failover | An API error qualifies for a model switch | Try the next approved model in priority order. OpenRouter documents rate limits, downtime, context validation errors, and moderation flags among its triggers. OpenRouter Model Fallbacks |
| Quality escalation | A returned answer fails the application’s check | Generate a new answer with the next candidate and apply the acceptance criteria again. FrugalGPT studies this kind of cascade. FrugalGPT |
For a provider chain, define the endpoint order, which errors advance the chain, and a deadline for the whole operation. Apply the workload’s eligibility rules to each attempt. In your logs, capture provider transitions and model transitions as distinct events so you can diagnose availability and answer quality separately.
Step 4. Account for the fallback that answered
OpenRouter’s Model Fallbacks documentation (accessed November 2026) says it prices the request using the model ultimately used and reports that model in the response body’s model field. Its example covers a free model followed by a paid model. If the paid model serves the fallback, OpenRouter says the request is billed at the paid model’s price. OpenRouter Model Fallbacks
For an application-managed cascade, record each API call under the same task ID. If the application pays for an initial generation and then a fallback generation, include both charges, even if the user sees only the fallback answer. Add any separately billed classifier or evaluator calls. Use reported usage and reconcile your totals against billing records. How to calculate LLM API cost
Step 5. Log the evidence and compare with a fixed model
Use the same acceptance rubric for the fixed-model baseline and the routed policy. Review results by workload, especially when a pooled average would combine requests with different deadlines or quality requirements. RouteLLM’s benchmark results varied by dataset and training data, so test each workload separately. LMSYS RouteLLM write-up
| Record | Fields to capture |
|---|---|
| Task | Task ID, workload, policy version, estimated input size, deadline, and acceptance rubric version |
| Decision | Eligible candidates, selected model, rule or score, and routing time |
| Attempt | Attempt order, requested and returned model, provider when available, usage, charge, elapsed time, and fallback reason |
| Outcome | Accepted, rejected, or failed, with the check result and elapsed time through the final outcome |
Calculate cost per accepted answer by dividing total cost for all tasks in a workload cohort by the number of accepted answers in that cohort. Include spend on rejected and failed tasks in the numerator. If no answers pass, report the spend and zero acceptances, and leave the ratio undefined. Cost per accepted task
Calculate quality escalation rate by dividing tasks that needed another model after a failed answer check by tasks that entered the quality cascade. Count tasks rather than attempts. Track provider failover separately, alongside overall acceptance rate and end-to-end latency. These are evaluation definitions for the application; keep the denominators and acceptance rubric fixed across policy versions.
When a fixed route is enough
Keep the fixed model when it meets the workload’s quality, latency, and cost targets and the routed policy offers too little improvement to justify maintaining it. Compare total spend and accepted outcomes for the same mix of tasks, then review the slow end of the latency distribution. If escalation is frequent, test sending that workload directly to the model it usually needs. If one workload label explains the difference, test a rule before training a router.
Sources
- RouteLLM open-source framework and benchmark results (LMSYS, July 1, 2024)
- RouteLLM on routing with preference data (arXiv 2406.18665, 2024; revised February 2025)
- FrugalGPT on reducing inference cost with cascades (arXiv, 2023)
- Auto Router (OpenRouter docs, accessed 2026-11-30)
- Model Fallbacks (OpenRouter docs, accessed 2026-11-30)
How this note was produced
Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.
How to Route LLM Requests by Workload. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/route-llm-requests-by-workload/