Skip to main content

Context Budget

Before selecting a model, the router checks whether the conversation fits in the model’s context window. Models that can’t fit the conversation are automatically excluded.
TokenSense applies a 10% safety margin — a model with a 100k context window is only used for conversations up to 90k tokens. If context_tokens is not provided, TokenSense estimates it from message content using a 4-chars-per-token approximation. Pass the exact count if you have it:

Per-Call Overrides

Override routing behaviour on a per-call basis.

Routing Decision

router.route() always returns a RoutingDecision object.
Every routing decision is also included in the CallEvent as routed_tier, so your output captures which tier was used for each call.

on_failure

Controls what happens when a model call fails.

Routing Decision

router.route() always returns a RoutingDecision object.
Every routing decision is also included in the CallEvent as routed_tier, so your output captures which tier was used for each call.