router
An intelligent, cost-saving local gateway. It sits transparently behind your Pi or Claude Code client. You keep your standard Pro subscriptions; the router decides which one to use per turn.
The Problem: Opaque Pricing & Token Limits
Frontier models are expensive. For example, Claude Fable 5 costs $10/1M input and $50/1M output. Running large codebases through it burns through your limits and credits instantly, even for simple formatting or refactoring tasks that don't require immense reasoning.
The Solution: Classifier Routing Architecture
Instead of routing everything to a frontier model, hirn_router uses a multi-step pipeline to evaluate, select, and execute the optimal model for each turn.
- 01 Lightweight classifier (effort/tier)
Receives the input, task features, and coarse budget descriptors. It evaluates these metrics and outputs a target model tier (e.g., extreme, high, medium, light, super_light).
- 02 Deterministic selector
Reads your user config mapping tiers to candidate models. It applies a scoring function based on latency, quality, cost, and live limits to pick one concrete model ID.
- 03 Pi executes the chosen model
Pi's model registry intercepts the decision and forwards the request to Fable, Opus, Gemini, or a local LLM based entirely on the deterministic routing output.
- 04 Logging for self-improvement
Logs the predicted tier, selection result, manual overrides, response times, and token usage. This data is fed back in to refine the classifier's tier prediction and adjust scoring weights per tier.
The Math: Weighted Normalized Sum
For the deterministic selector, hirn employs a clean, tuneable weighted-sum sorter. For each candidate model in the chosen tier, the router computes a score:
- Q Normalized quality (e.g., SWE-bench or agent scores).
- L Normalized latency from benchmarks (e.g. Flash vs Pro).
- C Expected marginal cost for the request (tokens × price).
- U Penalty for proximity to API plan and token limits.
It sorts by score and picks the top model. It's fully deterministic, transparent, and fast—adding no perceivable overhead to Pi's UX. If you're consistently hitting Claude limits, simply bump w_limit. If the model is too slow, bump w_l.
Cost Savings
By offloading heavy context tasks to workhorse models, the router cuts API costs by up to 80% while preserving high-tier reasoning.
Zero Latency
The ~26M parameter local classifier executes in less than 50ms on device, adding virtually zero overhead to your request pipeline.
Self-Improving
Local logging feeds directly back into the classifier, automatically refining its predictions over time based on your workflow.