---
title: Model Router
description: "Mudabbir's model router automatically classifies message complexity as SIMPLE, MODERATE, or COMPLEX using heuristic signals, then selects the optimal model size to balance cost and capability."
section: Advanced
ogType: article
keywords: ["model router", "automatic model selection", "complexity classification", "cost optimization"]
tags: ["advanced", "optimization"]
---

# Model Router

The Model Router automatically selects the appropriate model size based on message complexity, optimizing cost and latency.

<Callout type="warning">
  **Disabled by default.** Smart model routing is off by default because it conflicts with Claude Code CLI's built-in model routing. When using the Claude Agent SDK backend (recommended), Claude Code already picks the best model for each task. Enable the model router only if you want explicit control over model tiers or are using the Mudabbir Native backend.
</Callout>

## How It Works

The router classifies each message into one of three complexity levels:

| Level | Description | Typical Model |
|-------|-------------|---------------|
| `SIMPLE` | Greetings, simple questions, short responses | Smaller/faster model |
| `MODERATE` | Multi-step tasks, moderate reasoning | Default model |
| `COMPLEX` | Coding, deep analysis, multi-tool chains | Largest model |

## Classification Heuristics

The router uses several signals to determine complexity:

1. **Message length** — Longer messages tend to be more complex
2. **Keyword detection** — Certain words indicate complexity:
   - Code-related: "write code", "debug", "refactor", "implement"
   - Analysis: "analyze", "compare", "explain in detail"
   - Multi-step: "step by step", "plan", "research"
3. **Tool mentions** — References to specific tools suggest higher complexity
4. **Question depth** — Follow-up questions in a chain indicate growing complexity

### Threshold

A message is classified as COMPLEX if it has at least 1 complex signal AND is longer than 30 characters.

## Configuration

The model router is **disabled by default** (`smart_routing_enabled: false`). Enable it in the dashboard under Settings → Behavior & Safety, or via environment variable:

```bash
export MUDABBIR_SMART_ROUTING_ENABLED=true

# Customize model tiers
export MUDABBIR_MODEL_TIER_SIMPLE="claude-haiku-4-5-20251001"
export MUDABBIR_MODEL_TIER_MODERATE="claude-sonnet-4-5-20250929"
export MUDABBIR_MODEL_TIER_COMPLEX="claude-opus-4-6"
```

The router works with the Claude Agent SDK and Mudabbir Native backends.

## Example Classifications

| Message | Classification |
|---------|---------------|
| "Hi!" | SIMPLE |
| "What time is it?" | SIMPLE |
| "Write a Python web scraper that handles pagination" | COMPLEX |
| "Analyze the performance of my database queries" | COMPLEX |
| "Search for news about AI" | MODERATE |

<Callout type="info">
  The model router is a heuristic system. For most users, leaving it disabled and letting Claude Code handle model selection produces the best results. Enable it only if you want to optimize API costs or need explicit control over which models are used for different task types.
</Callout>

<Callout type="warning">
  **Ollama users:** The model router is automatically skipped when using Ollama, since Ollama runs a single local model. There are no tiers to route between.
</Callout>
