What Is an LLM Router? Automatic Model Routing for Cost and Quality

Most prompts in a coding session are easy. Without routing, every request hits the most expensive model. An LLM router scores each prompt for difficulty, ambiguity, and domain in ~180ms and returns the model to call. In a worked example at November 2026 Claude rates, routing cuts spend 55% after router fees.

March 31, 2026 · 2 min read
What Is an LLM Router? Automatic Model Routing for Cost and Quality

You are paying $20 per million output tokens for Claude Opus 5.5 to add a TODO comment. To rename a variable. To fix a typo in a docstring. Claude Haiku 5.5 handles those at $0.50/M output tokens. An LLM router fixes this by classifying prompt difficulty in ~180ms and naming the cheapest model that can handle each request. In the worked example below, that cuts spend 55% after router fees.

55%
Lower spend in the worked example
~180ms
Classification latency
65,536
Max input tokens per call
$0.005
Per routing request

The Problem: Paying Top Dollar for Simple Tasks

Most prompts in a coding session are simple. Adding imports. Writing boilerplate tests. Renaming variables. Generating docstrings. Fixing lint errors. These tasks need little reasoning, and a $0.50/M-output model writes the same import line as a $20/M-output one.

Without routing, every request goes to the same model. If your agent is configured to use Claude Opus 5.5, that is what it uses for everything. The TODO comment costs the same per token as a complex architectural refactor.

This waste compounds fast. A typical coding agent session involves 50-200 LLM calls. If 60% of those are easy tasks sent to Opus 5.5 instead of Haiku 5.5, you pay 40x more than necessary on most of your requests.

The prompt difficulty distribution

Analysis of millions of coding prompts shows a consistent distribution: roughly 60% easy, 25% medium, 15% hard. The ratio shifts depending on the task (greenfield coding skews harder, maintenance and refactoring skew easier), but the pattern holds. Most work is simple.

What an LLM Router Does

An LLM router is a classification layer between your application and the model providers. Before each LLM call, the router examines the prompt and assigns a difficulty level. That difficulty level maps to a model tier. The application then sends the request to the recommended model instead of a fixed default.

The classification happens on the prompt text, system prompt, and conversation history. The router does not proxy the LLM request itself. It returns a model recommendation, and your application makes the actual API call to the provider. This keeps the router lightweight: it only needs to see the input, not handle streaming, function calls, or response parsing.

Four classification categories cover the space:

Easy

Boilerplate, simple edits, documentation, formatting, imports, renaming. These need token prediction, not reasoning. Route to the smallest, cheapest model.

Medium

Multi-file changes, moderate logic, standard patterns with some nuance. Requires understanding of code structure but not deep reasoning. Route to a mid-tier model.

Hard

Architectural decisions, complex debugging, large refactors across many files, novel algorithms. These require the full reasoning capability of a frontier model.

Needs Info

Ambiguous prompts where classification is uncertain. Instead of guessing, return to the user for clarification. This avoids wasting tokens on a misrouted request.

The "needs_info" category is important. A prompt like "fix it" with no context is unclassifiable. Routing it to a cheap model wastes tokens on a bad response. Routing it to an expensive model wastes money on a bad response. The correct action is to ask the user what they mean.

The difficulty tiers map to models through a policy you control. The grid below is what an admin configures: each classified difficulty × ambiguity points at a model and a reasoning effort, with domain overrides matched first. Routine turns drop to the cheap tier; only hard work reaches the frontier model.

Routing matrix
Each classified difficulty × ambiguity maps to a Claude model and reasoning effort. Domain overrides match first, then this grid.
Difficulty \ Ambiguity
Clear
Some ambiguity
Vague
Easy
Trivial edits, formatting, simple lookups
Haiku
Low
Haiku
Medium
Haiku
High
Medium
Typical feature work and multi-file edits
Sonnet
Low
Sonnet
Medium
Sonnet
High
Hard
Architecture, tricky debugging, large refactors
Opus
Low
Opus
Medium
Opus
High
Domain overrides
Summary
Haiku
Medium
The routing policy an admin configures. Each difficulty × ambiguity maps to a model tier and reasoning effort; an unmatched turn falls to the defaults.

How Routing Works Internally

The router is a trained classifier, not a set of heuristics. Rule-based approaches (keyword matching, prompt length, regex patterns) are fast but inaccurate. A short prompt can be extremely hard ("refactor this to use the visitor pattern") and a long prompt can be trivially easy (a large block of boilerplate with "add error handling to each function").

Morph's router is trained on millions of coding prompts with labeled difficulty. The training data comes from real coding sessions across multiple languages, frameworks, and task types. Each prompt is paired with the model tier that produced the best cost-quality tradeoff for that specific task.

The classifier runs in ~180ms average latency. For comparison, most LLM API calls take 1-10 seconds for time-to-first-token, so the classification overhead is a fraction of the total request time. In practice, the classification runs in parallel with request preparation (building the message array, fetching context from files, assembling the system prompt), making the effective overhead near zero.

Router classification flow

// 1. User submits a prompt
const userQuery = "Add a TODO comment above the fetchUsers function"

// 2. Router classifies difficulty (~180ms, runs in parallel with step 3)
const routing = fetch("https://api.morphllm.com/v1/router/multimodel", {
  method: "POST",
  headers: { Authorization: `Bearer ${MORPH_API_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ input: userQuery, allowed_providers: ["anthropic"] }),
}).then((res) => res.json())

// 3. Meanwhile, prepare the request (context fetching, system prompt, etc.)
const messages = await buildMessages(userQuery, context)

// 4. Send to the recommended model
const { model, difficulty } = await routing // difficulty: "easy"
const response = await anthropic.messages.create({
  model, // a cheap tier for an easy prompt
  max_tokens: 1024,
  messages,
})
// The router only returns a model name. Your code makes the LLM call.

The parallel execution is key. If you run classification sequentially before the LLM call, you add 180ms to every request. If you run it in parallel with the work you were already doing (fetching file contents, building context, preparing the system prompt), the classification completes before the request is ready to send. Zero added latency in the common case.

Model Tiers and Pricing

The router maps each difficulty level to a model tier. The specific models within each tier vary by provider (Anthropic, OpenAI, Google), but the cost-quality tradeoff follows the same structure.

Difficulty to model tier mapping, November 2026
DifficultyAnthropic exampleInput / output per MMorph balanced pick (low ambiguity)
EasyClaude Haiku 5.5$0.10 / $0.50deepseek-v4-flash
MediumClaude Sonnet 5.5$2 / $10glm-5.2
HardClaude Opus 5.5$4 / $20glm-5.2
Needs InfoYour default model—default_model

Haiku 5.5 to Opus 5.5 is a 40x price gap on input and on output. Sonnet 5.5 to Opus 5.5 is 2x. Those gaps make routing profitable even with imperfect classification, because every easy prompt caught moves spend off the 40x tier. Rates are from Anthropic's pricing page, checked November 3, 2026.

Morph's balanced policy is not limited to one vendor. At low ambiguity it sends easy work to deepseek-v4-flash and medium and hard work to glm-5.2. High-ambiguity prompts escalate to claude-fable-5, the strongest model for prompts whose intent is unclear.

Provider-specific routing

New integrations call POST /v1/router/multimodel and restrict candidates with allowed_providers, for example ["anthropic"]. The older morph.routers.anthropic.selectModel(), morph.routers.openai.selectModel(), and morph.routers.gemini.selectModel() SDK methods remain for backwards compatibility.

Cost Savings Math

Assume a coding agent session with 100 LLM calls, each with 3,000 input tokens and 1,000 output tokens. Without routing, all 100 calls go to Claude Opus 5.5 at $4 input and $20 output per million tokens, or $0.032 per call.

Cost comparison: no routing vs routing, November 2026 Claude rates
ScenarioModelCallsCost per callCost
No routing (all Opus)Opus 5.5 ($4/$20)100$0.032$3.20
Easy (60%)Haiku 5.5 ($0.10/$0.50)60$0.0008$0.048
Medium (25%)Sonnet 5.5 ($2/$10)25$0.016$0.40
Hard (15%)Opus 5.5 ($4/$20)15$0.032$0.48
Router feesMorph Router100$0.005$0.50
Routing totalMixed100—$1.43

$3.20 without routing. $0.93 in model spend with routing, and $1.43 once the $0.50 of router fees is added. Net spend drops 55%.

The fee is per request, not per token, so it weighs most on short calls. One Haiku 5.5 call in this example costs $0.0008, and the routing decision for it costs $0.005. Classify once per user turn or per task instead of once per tool call, and hold the current model once a session's context grows large, where switching would throw away the prompt cache.

At 10,000 sessions per month, spend falls from $32,000 to $14,300, including $5,000 in router fees for 1,000,000 requests. A harder mix (50% easy, 20% medium, 30% hard) costs $1.82 per session after fees, still 43% below all-Opus.

40x
Price gap: Haiku 5.5 vs Opus 5.5
55%
Lower spend, 60/25/15 mix
$0.50
Router fees per 100 calls
43%
Lower spend, 50/20/30 mix

Classification Approaches

Not all routing implementations are equal. The accuracy and speed of the classifier determines whether routing saves money or degrades quality.

Prompt classification methods
MethodLatencyAccuracyTradeoff
Keyword/regex matching<1msLow (50-65%)Fast but misclassifies semantic difficulty. 'refactor' is not always hard.
Prompt length heuristics<1msLow (45-60%)Long prompts can be easy (boilerplate). Short prompts can be hard.
Small classifier model50-200msMedium (70-80%)Better accuracy but adds latency. General-purpose, not domain-tuned.
Trained domain classifier200-500msHigh (85-95%)Best accuracy. Requires domain-specific training data. Morph's router uses this approach.
LLM-as-judge1-5sHigh (85-90%)Uses a cheap LLM to classify. Accurate but slow. The classification latency may exceed the savings.

The keyword approach fails on semantic difficulty. "Add error handling" might be easy (wrapping a function in try-catch) or hard (designing a retry strategy with exponential backoff, circuit breakers, and graceful degradation). No keyword can distinguish these without understanding the context.

The LLM-as-judge approach is accurate but slow. Using a small LLM to classify before routing to a frontier model adds 1-5 seconds per request. If the average request takes 3 seconds, you have doubled the latency for a subset of requests. The cost of the classification call itself also reduces net savings.

Trained domain classifiers hit the practical sweet spot. Morph's classifier processes the prompt in ~180ms, which hides behind parallel request preparation. It is trained on millions of real coding prompts, so it understands that "add a TODO" is easy while "refactor the authentication flow to support SSO" is hard, regardless of prompt length or keywords.

Routing Modes and Policies

Different workloads want different cost-quality tradeoffs. A developer writing production code wants quality. A CI pipeline generating tests wants cost efficiency. Morph's router exposes this as a policy parameter with four values.

balanced (default)

Picks by difficulty, ambiguity, and cost, and ignores domain. Returns the same model for every domain at a given difficulty and ambiguity.

cost_efficient

Same coverage test as balanced with a cheaper tie-break. Drops a tier rather than pay for headroom. Suited to batch jobs, CI, and evals.

capability_heavy

Domain-aware and cost-blind. Returns the strongest in-domain model for the request.

domain_skills

Domain-aware and cost-aware. Returns the cheapest in-domain specialist that still covers the difficulty tier.

Selecting a routing policy

const res = await fetch("https://api.morphllm.com/v1/router/multimodel", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MORPH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    input: userQuery,
    policy: "cost_efficient", // or "balanced", "capability_heavy", "domain_skills"
  }),
})
const { model, difficulty, ambiguity, domain } = await res.json()

Switching from balanced to cost_efficient moves five cells of the routing matrix to cheaper models. A medium, low-ambiguity prompt drops from glm-5.2 to deepseek-v4-pro, for example, and a hard, medium-ambiguity prompt drops from claude-opus-4-8 to glm-5.2.

Implementation

Adding routing to an existing application takes minimal code changes. The router is a single API call that returns a model name. You replace your hardcoded model string with the router's recommendation.

Full implementation with Morph SDK

import Anthropic from '@anthropic-ai/sdk'

const anthropic = new Anthropic()

async function pickModel(input: string) {
  const res = await fetch("https://api.morphllm.com/v1/router/multimodel", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.MORPH_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      input,
      allowed_providers: ["anthropic"],
      default_model: "claude-opus-4-8", // returned when difficulty is needs_info
    }),
  })
  return res.json() // { model, difficulty, ambiguity, domain, ... }
}

async function chat(userQuery: string, conversationHistory: Message[]) {
  const { model } = await pickModel(userQuery)

  // Use the selected model for the actual request
  return anthropic.messages.create({
    model,
    max_tokens: 4096,
    messages: [
      ...conversationHistory,
      { role: 'user', content: userQuery }
    ]
  })
}

// "Add a TODO comment" → difficulty: "easy", cheapest allowed model for the tier
// "Debug this race condition in the distributed lock" → difficulty: "hard"
// "fix it" → difficulty: "needs_info", model: your default_model

For applications that already use a model configuration variable, the change is a one-line replacement. Instead of const model = "claude-opus-4-8", you use const { model } = await pickModel(input). Everything downstream stays the same.

Parallel classification pattern

To avoid adding latency, run the classification in parallel with your request preparation:

Zero-latency routing with parallel classification

async function chatWithParallelRouting(userQuery: string) {
  // Run classification and context preparation in parallel
  const [routerResult, context] = await Promise.all([
    pickModel(userQuery),
    fetchRelevantContext(userQuery),  // File reads, search, etc.
  ])

  // Both complete. Build and send the request.
  const response = await anthropic.messages.create({
    model: routerResult.model,
    messages: buildMessages(userQuery, context),
    max_tokens: 4096,
  })

  return response
}

When Not to Route

Routing is not always the right choice. Some scenarios benefit from a fixed model.

All prompts are hard

If your application exclusively handles complex reasoning tasks (theorem proving, novel algorithm design), routing will classify everything as hard and add overhead without savings.

Latency is critical

For real-time applications where every millisecond matters (autocomplete, inline suggestions), the 180ms classification overhead may not be acceptable even with parallel execution.

Low volume

If you make fewer than 1,000 LLM calls per month, the absolute savings from routing may not justify the integration complexity. The percentage savings are the same, but $50/month saved may not matter.

For most applications, routing is worth it. The threshold is roughly: if more than 30% of your prompts are easy or medium difficulty, and you make more than a few thousand LLM calls per month, routing pays for itself within the first day.

One rule applies to every routed multi-turn session: each model keeps its own prompt cache, so switching models mid-conversation re-prefills the whole context at full input price. Classify once at the session boundary and hold the model; the arithmetic is on the prompt caching and cache-aware routing page.

For multi-agent workloads — where a planner orchestrates a team of executor agents — the routing decision also applies at the architectural level: assign the frontier model to planning turns only, and a cheaper model to all execution turns. A typical app build uses 4M tokens on planning and 10M on execution; routing the executor to Haiku 4.5 saves 57% on top of per-turn routing savings. See Multi-Agent Model Routing and the full benchmark leaderboard.

Frequently Asked Questions

What is an LLM router?

An LLM router classifies each prompt and picks the model tier that should answer it. Easy prompts go to cheap models like Claude Haiku 5.5 at $0.10/$0.50 per million tokens. Hard prompts go to strong models like Claude Opus 5.5 at $4/$20. Morph's router returns its pick in ~180ms for $0.005 per request.

How much does LLM routing save on API costs?

It depends on the prompt mix and the router fee. In the worked example above (100 calls, 60% easy, 25% medium, 15% hard), routing across Haiku 5.5, Sonnet 5.5, and Opus 5.5 cuts the bill from $3.20 to $1.43 after $0.50 of router fees, 55% lower. A harder 50/20/30 mix saves 43%.

Does routing add latency to LLM requests?

Morph's router classifies prompts in ~180ms average. Run the classification in parallel with request preparation (context fetching, system prompt assembly) and the effective added latency is near zero. The classification finishes before the request is ready to send.

What classification categories does an LLM router use?

Four tiers: easy (boilerplate, simple edits, documentation), medium (multi-file changes, moderate logic), hard (architectural decisions, complex debugging, large refactors), and needs_info (ambiguous prompts that should be returned to the user for clarification).

How accurate is prompt difficulty classification?

Morph's classifier is trained on millions of coding prompts and returns a confidence score with each label. When difficulty does not clear the confidence threshold, the router returns needs_info and your default_model instead of guessing.

Can I use an LLM router with any model provider?

Yes. The router returns a model recommendation (for example deepseek-v4-flash, glm-5.2, or claude-opus-4-8). You pass that model name to whichever provider SDK you use. The router does not proxy the actual LLM request. It only classifies and recommends.

What routing policies does Morph's router support?

Four. balanced (the default) and cost_efficient ignore domain; cost_efficient drops a tier rather than pay for headroom. capability_heavy returns the strongest in-domain model regardless of cost. domain_skills returns the cheapest in-domain specialist that still covers the difficulty tier.

Related Resources

Stop Paying Frontier Prices for Simple Tasks

Morph's LLM router scores prompt difficulty, ambiguity, and domain in ~180ms and returns the model to call, for $0.005 per request. Trained on millions of coding prompts. Four policies: balanced, cost_efficient, capability_heavy, and domain_skills.