The right model.
Every time.
Hybrid routing: a fast lexical classifier picks topic and complexity, a D1 shortlist narrows by budget, an embedding reranker scores semantic match. No vendor-aligned bias. Routes refresh daily from real benchmarks.
Four stages. Under a second.
Lexical prefilter
Keyword classifier scores topic (code/math/science/writing/general + 19 subcategories) and complexity tier (SIMPLE/MEDIUM/COMPLEX/REASONING) in under 1ms.
D1 shortlist
Query 345+ benchmark-scored models. Filter by budget tier and complexity-weighted quality+value blend. Cap output_price per tier to protect margin.
Embedding reranker
Workers AI bge-base-en-v1.5 embeds the prompt, cosine-ranks the shortlist. Combines semantic match (0.55) + value (0.35) + reliability (0.10).
Direct or fallback
If model is OpenAI / Anthropic / Google / DeepSeek / xAI — direct provider call (no OpenRouter markup). Long tail goes via OpenRouter. Circuit breaker with top-3 failover.
Full routing transparency.
{
"choices": [{ "message": { "content": "..." } }],
"routing": {
"selected_model": "google/gemini-2.5-flash",
"topic_detected": "code/frontend",
"topic_confidence": 0.87,
"complexity_tier": "MEDIUM",
"complexity_confidence": 0.91,
"is_agentic": false,
"estimated_cost_usd": 0.0003,
"charged_cost_usd": 0.002,
"savings_vs_gpt4_pct": 92,
"call_path": "direct:google",
"models_considered": 12,
"candidate_models": [ "...", "...", "..." ],
"data_source": "d1_semantic"
}
}