Complexity-Based Cheap/Strong Model Router
Route easy requests to a cheap model and hard ones to a strong model using a lightweight classifier plus escalation.
Strategy
- Heuristic pre-filter (length, presence of code, math, multi-step words).
- Cheap classifier call returns
simpleorcomplex. simple→ cheap model;complex→ strong model.- Escalate: if the cheap model's answer fails validation (schema error, low self-reported confidence, tests fail), retry on the strong model.
Router
def route(prompt: str) -> str:
if len(prompt) > 6000 or "```" in prompt:
return "strong"
label = classify(prompt) # cheap model, max_tokens=1, temperature=0
return "strong" if label == "complex" else "cheap"
CLASSIFIER_PROMPT = """Label the task as 'simple' (lookup, rewrite, short answer)
or 'complex' (multi-step reasoning, code, math, analysis). Reply with one word.
Task: {prompt}"""Config
models: {cheap: small-fast-model, strong: frontier-model}
escalate_on: [json_parse_error, validator_fail]
log: [route, model, tokens_in, tokens_out, latency_ms, escalated]Measure on your own traffic: compare quality on a sample before trusting the savings.
Failure modes
- Classifier misroutes hard requests to the cheap model; escalation on validation failure is required.
- Escalation doubles latency and cost for misrouted requests.
- Routing thresholds drift as models change; re-check against logged traffic.
Markdown version: /blueprints/complexity-based-routing.md
Want a deeper build of this?
Vote for an extended, fully tested version (more tools, a full workflow file). Votes decide what we build next.
Get one fully built blueprint a week
A weekly email: one blueprint with config, cost, setup time and failure modes, plus a vote on what we build next.
Related blueprints
LiteLLM Proxy with Fallbacks and Load Balancing
An OpenAI-compatible gateway that load-balances deployments and falls back across providers on errors.
Local-First Routing with Ollama and Cloud Fallback
Serve requests from a local Ollama model, falling back to a cloud model only when local fails or the task needs it.
OpenRouter Model Fallback and Provider Ordering
Use OpenRouter's request-level models array and provider preferences for automatic failover.