Resource-Aware Optimization

Route by difficulty. Pay for what the task needs.

A router scores each request's complexity and dispatches it to the cheapest model that still meets the quality bar, under explicit token / time / cost budgets, using prompt caching and model cascades.

Level
02 · Workflow
Also known as
Model Routing, Cost-Aware Routing, LLM Router, Model Cascade
Trade-off
Large cost savings are gained against the effort of tuning and continuously validating the complexity rubric.
Native in
RouteLLM
The mental model

A shape you can draw on a napkin.

A router scores request complexity and dispatches to the cheapest model that meets the quality bar; a failed quality check cascades up to a stronger model.

simplesimplecomplexcomplexComplexityRouterCheap ModelStrong Model
Walk it through

A real run, step by step.

TaskA support desk answers 1,000 requests a day. A router rates each request and sends it to the cheapest model that can handle it:
Illustrative prices. Routed: 14.70 USD per day. Everything on the large model: 90.00 USD.
Request typeShareModelUSD per day
Order status, password reset60%Small1.20
Returns with a policy lookup30%Medium4.50
Contract disputes10%Large9.00
What this shows: the saving comes from the 90% of requests that never needed the large model. It rests entirely on the router's rating. A contract dispute rated as simple gets a cheap answer that is wrong, and nothing in the cost report shows it. That is why the cascade in the code checks each reply and escalates when the check fails.
In code

The pattern in code.

Plain Pythonpython
MODELS = ["small", "medium", "large"]  # cheapest first

def answer(request, budget_usd=0.10):
    # 0, 1 or 2: a rule or one cheap call
    start = classify_complexity(request)
    spent = 0.0
    for name in MODELS[start:]:
        reply, cost = call(name, request)
        spent += cost
        if passes_check(reply) or spent >= budget_usd:
            return reply  # good enough, or the budget is used up
    return reply  # the cascade ended at the largest model
Fit

Use it, or not.

When to reach for it

  • Request volume is high with mixed difficulty.
  • Cost is a first-order constraint.
  • A cheaper model handles a meaningful share of traffic without quality loss.

When it backfires

  • Every task needs the top model.
  • The complexity rubric is unstable — mis-route cost exceeds the savings.
  • The latency of an extra routing hop is unacceptable.
Pitfalls

Three ways this pattern will hurt you.

Routing on the model's own confidence

Asking the LLM 'how confident are you, 1–10?' to decide routing is hallucination-prone and unstable; the router itself becomes the weakest link.

Countermeasure

Score complexity with a deterministic / statistical classifier (length, task type, historical difficulty) and validate routes against a quality signal rather than self-reported confidence.

Silent quality erosion on the cheap path

Once most traffic is routed to the cheap model, regressions there go unnoticed — nobody is watching the cheap path.

Countermeasure

Sample and evaluate cheap-path outputs continuously (golden tests / LLM-as-judge) and fall back to the strong model when the quality bar is missed.

A rubric that rots as the model fleet changes

A complexity rubric tuned for one model pair silently misroutes once a new, cheaper model matches the old expensive one — or a price change inverts the cost math.

Countermeasure

Pin the rubric to a fixed evaluation set and re-benchmark whenever the model fleet or pricing changes; treat the rubric as versioned configuration, not a constant.

Framework support

Where Resource-Aware Optimization is native.

RouteLLMLibrarypreference-trained router across a cheap/strong model pairNative
OpenRouterServicegateway-level model routingAdaptable
LangGraphas custom conditional edgesAdaptable
Sources

Where this pattern comes from.

  1. RouteLLM: Learning to Route LLMs with Preference DataIn the source list
  2. Cost-Aware Contrastive Routing for LLMsIn the source list
  3. Agentic Design PatternsIn the source list

Search

Search patterns, frameworks, and pages.