# Model Routing

> The Model Routing is a technique of sending each request to the most suitable model based on task, cost or speed.

## What is model routing in LLM apps?

The technique of automatically choosing a model for each request: simple tasks go to a small, cheap model and complex ones to a frontier model. Reduces costs and latency without losing quality where it matters.

- Topic: APIs & Integrations
- Type: technique

## Example

Wrong:

```js
const model = prompt.length > 500 ? 'large-model' : 'small-model';
return complete(model, prompt);
```

Right:

```js
const route = classify(prompt);
const model = route === 'complex' ? 'large-model' : 'small-model';
log({ route, model });
try {
  return await complete(model, prompt);
} catch {
  return complete('fallback-model', prompt);
}
```

The route is chosen by task, logged for review and backed by a fallback model on errors.

## Common mistakes

- Sending hard tasks to a small model to save money and losing quality without noticing.

## Key points

- The routing rule is explicit and logged, so you can see which model handled each request.
- Every route has a fallback model for errors and timeouts.
- Routing decisions are checked with evals, not only by cost.

## Interview questions

### How does a model router decide which model to use?

Common methods are rules by task type, a small classifier model that rates difficulty, or trying a cheap model first and escalating if the answer fails a check.

### Model routing vs fallback: what is the difference?

Routing picks the best model before the request. Fallback switches to another model only after the chosen one fails or times out.

### Does model routing hurt answer quality?

It can if hard tasks go to a small model. Run evals per route to confirm quality holds where it matters.

## Related cards

- [AI Gateway](https://wonderium.dev/ai/ai-gateway.md)
- [Small Language Model](https://wonderium.dev/ai/small-language-model.md)
- [Token Cost](https://wonderium.dev/ai/token-cost.md)
- [Evals](https://wonderium.dev/ai/evals.md)
- [Reasoning Model](https://wonderium.dev/ai/reasoning-model.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/model-routing
- Last updated: 2026-11-25
