Skip to main content

Router

The routing layer. Selects the right model for each call based on rules, context budget, and cost constraints. Runs entirely in-process.

Why routing matters

Naive routing — “short prompt = cheap model” — silently breaks things:
  • A 150k token conversation sent to a model with an 8k context window gets truncated without warning
  • Switching from Sonnet to Haiku for a complex multi-constraint prompt causes capability regression
  • There is no way to know routing failed until a user reports a wrong answer
TokenSense’s router checks the context budget before routing and escalates automatically on failure.

Basic setup

Getting a routing decision

Making the call with the routed model


Tiers

A tier is a named group of models. Models within a tier are tried in order — the first one whose context window fits the conversation is selected.
Tier order matters. The router tries tiers from first to last in the dict. Earlier tiers are preferred unless rules say otherwise.