Route by Complexity
"Not every task needs Sonnet."
The Problem
"Fix this typo" → Claude Sonnet → $0.18
"Fix this typo" → Free model → $0.00
Same result. 100% cost difference.
The Routing Logic
Cost Per Model ($/MTok input)
Same task, different models — quality vs cost tradeoff:
Sonnet is 12x more expensive than Haiku for ~same quality on routine tasks.
Free models handle 60-70% of coding tasks without noticeable quality loss.
Big-T: Classify Complexity First
The Tokenomics Foundation defines the Big-T Framework — "Big-O for tokens." Classify your workload's complexity class before routing, so you can see the cost curve before the invoice arrives:
Route by complexity is Big-T(n·k·a) intelligence. The complexity scorer decides which class a workload falls into; the Big-T class decides what it will cost. Big-T is the pre-routing classification the Tokenomics Foundation standardizes; routing is your execution of it.
DIY: 246 Lines
The Styrr pattern — ordered model array with automatic fallback:
import { StyrRouter } from 'styrr';
const router = new StyrRouter({
apiKey: process.env.OPENROUTER_API_KEY,
models: [
// Cheapest first — fallback on 429/5xx/timeout
{ id: 'meta-llama/llama-3.3-70b-instruct:free' },
{ id: 'google/gemma-4-27b-it:free' },
{ id: 'anthropic/claude-3.5-haiku' }, // paid fallback
{ id: 'anthropic/claude-sonnet-4' }, // premium last resort
],
hooks: {
onFallback: (failed, next) =>
console.log(`${ failed } failed, trying ${ next }`),
}
});
// Router auto-tries each model in order.
// Free model rate-limited? → next free → haiku → sonnet.
// You pay premium ONLY when free models are unavailable.npm i @carloscortezcloud/styrr-llmThe Strategy That Saves 70%
Don't pick one model. Pick an order.
Most tasks succeed on the first (free) model. When it fails (rate limit, quality issue), the router automatically falls to the next. You only pay premium when absolutely necessary.
Result: 70% of calls cost $0. 25% cost $0.25/MTok. Only 5% hit premium.