← Back to Manifesto

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

TASK (input)
COMPLEXITY SCORER
Simple
typos, formatting, simple questions
FREE Llama 70B, Gemma, Qwen $0/MTok
Medium
code generation, refactoring
MID Haiku, Flash, Mini $0.07-0.25/MTok
Complex
architecture, debug, multi-file
PREMIUM Sonnet, GPT-4o $2.5-3.0/MTok

Cost Per Model ($/MTok input)

Same task, different models — quality vs cost tradeoff:

Claude Sonnet 4 Premium
$3.00
★★★★★
GPT-4o Premium
$2.50
★★★★★
Claude Haiku Mid
$0.25
★★★★☆
Gemini Flash Mid
$0.07
★★★★☆
Llama 3.3 70B Free
FREE
★★★★☆
Qwen 3 32B Free
FREE
★★★☆☆

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:

T(1) Constant The model is not called per request — cache hit, static lookup. Lever: cache and precompute
T(log n) Sublinear Deterministic code shrinks the input before the model sees it. Lever: filter before inference
T(n) Linear One model call per request — the healthy default. Lever: trim per-call overhead
T(n·k) Multiplicative k model calls per request — and k is usually invisible. Lever: compose tool pipelines
T(n·k·a) Agent-multiplicative An orchestrator spawns sub-agents that spawn tool calls. Lever: bound depth, add budgets
T(∞) Unbounded Loops with no termination condition. Lever: hard termination. Always.

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:

styrr-pattern.ts
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.
install
npm i @carloscortezcloud/styrr-llm

The 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.

Styrr on GitHub → Next: Audit Monthly →