Smart Cost Routing
Introduction
Section titled “Introduction”Smart Cost Routing analyzes prompt complexity and intent, then selects an eligible model balancing quality, availability and cost. It combines curated benchmark data, real-time feedback from your users, and multi-armed bandit exploration to continuously improve routing decisions.
Smart Cost seeks cheaper eligible models while respecting quality and exploration limits. Complex requests bypass cost optimization and continue through the governing routing strategy.
How It Works
Section titled “How It Works”Every request passes through six stages before a provider is called:
Request → Complexity & Intent Classification → Candidate Filtering → Scoring → Selection → Provider Call → Feedback Loop- Complexity Classification scores the prompt on a 0-to-1 scale using weighted heuristics.
- Intent Detection identifies the task type (code, math, reasoning, general).
- Candidate Filtering removes models that are too expensive or too low quality.
- Scoring ranks remaining candidates using benchmark data, feedback history, and cost savings.
- Selection picks a model via exploit/explore strategy.
- Feedback Loop records outcome data that improves future decisions.
Complexity Classification
Section titled “Complexity Classification”Every prompt receives a complexity score between 0 and 1 based on a weighted heuristic analysis. Each signal is normalized to a 0-1 range, then multiplied by its weight.
| Signal | Weight | How Measured |
|---|---|---|
| Message count | 30% | Normalized across 1-5 messages |
| System prompt length | 25% | Normalized across 0-300 tokens |
| Tool usage | 20% | Binary: 1 if tools are present, 0 otherwise |
| Code blocks | 15% | Binary: 1 if ``` detected in content, 0 otherwise |
| Token count | 5% | Normalized across 10-500 tokens |
| JSON output | 5% | Binary: 1 if response_format is set, 0 otherwise |
The weighted sum maps to one of three tiers:
| Tier | Score Range | Behavior |
|---|---|---|
| Simple | < 0.3 | Ranks eligible Simple candidates by value |
| Moderate | 0.3 - 0.7 | Ranks eligible Moderate candidates by value |
| Complex | > 0.7 | Bypasses cost optimization; continues through the governing strategy |
Complex prompts bypass Smart Cost and continue with Feedback-driven or the declared rule strategy.
Intent Detection
Section titled “Intent Detection”In parallel with complexity scoring, the classifier detects the task type by scanning message content for keywords and structural signals. The detected intent determines which benchmarks matter most when scoring candidate models.
| Intent | Detected From | Priority |
|---|---|---|
| Code | Code blocks, function, def, class, import, compile, debug, refactor | Highest |
| Math | ∫, ∑, integral, equation, derivative, calculate, probability, theorem | High |
| Reasoning | Tool usage, step by step, analyze, reason, compare, evaluate | Medium |
| General | Default when no specific intent is detected | Lowest |
Priority determines which intent wins when multiple are detected. A prompt containing both code blocks and the word analyze is classified as Code, not Reasoning.
Model Intelligence: Benchmark Data
Section titled “Model Intelligence: Benchmark Data”This is the core of Smart Cost Routing. The system maintains a curated database of model capabilities, scored across standardized benchmarks. This data drives the quality estimation that makes routing decisions possible.
Where We Source Benchmark Data
Section titled “Where We Source Benchmark Data”Benchmark scores are aggregated from multiple authoritative sources and cross-referenced for accuracy:
- Provider documentation (official model cards from OpenAI, Anthropic, Google, etc.)
- HuggingFace Open LLM Leaderboard
- Epoch AI Benchmarks
- Artificial Analysis
- LLM Stats / Klu AI / Onyx Leaderboards
When sources disagree, we use the provider’s official numbers as the primary reference and flag discrepancies for manual review.
What Benchmarks We Track
Section titled “What Benchmarks We Track”Each benchmark measures a specific capability. The routing system uses different benchmarks depending on the detected intent.
| Benchmark | What It Measures | Used For Intent |
|---|---|---|
| MMLU | General knowledge across 57 subjects | General, Reasoning |
| GPQA | Graduate-level expert Q&A | Reasoning, Math |
| HumanEval | Python code generation (pass@1) | Code |
| SWE-bench | Real GitHub issue resolution | Code |
| LiveCodeBench | Contemporary coding problems | Code |
| MATH | Competition-level mathematics | Math |
| AIME 2025 | American Invitational Math Exam problems | Math |
| MMLU-Pro | Harder MMLU variant with 10 answer choices | Reasoning |
| IFEval | Instruction following accuracy | General |
| HellaSwag | Commonsense reasoning | General |
| ARC | AI2 Reasoning Challenge | Reasoning |
Benchmark coverage depends on the deployed catalog. Models without benchmark data receive a default score of 0.5 (neutral, neither boosted nor penalized).
How Data Is Curated
Section titled “How Data Is Curated”The Midas aggregation system fetches pricing and benchmark data for all supported models. Each model entry contains:
- Pricing: input, output, and cached token costs
- Benchmarks: normalized to a 0-1 scale for cross-model comparison
- Capabilities: context window, multimodal support, function calling
- Strengths and weaknesses: qualitative notes per model
- Recommendations: suggested use cases
Data is refreshed whenever providers publish updates. The full dataset is embedded in the gateway binary at build time, enabling zero-latency lookups with no external API calls during request routing.
Benchmark-Weighted Quality Score
Section titled “Benchmark-Weighted Quality Score”The quality score for a given model and intent is computed as a weighted average of available benchmark scores:
benchmark_score = Σ(vᵢ × wᵢ) / Σ(wᵢ)Where vᵢ is the model’s score on benchmark i and wᵢ is the weight for that benchmark given the detected intent. The denominator sums only the weights of benchmarks that are actually present for the model, so missing benchmarks do not penalize the score.
Intent Weight Tables
Section titled “Intent Weight Tables”Code Intent:
| Benchmark | Weight |
|---|---|
| HumanEval | 35% |
| SWE-bench | 30% |
| LiveCodeBench | 20% |
| MMLU | 10% |
| IFEval | 5% |
Math Intent:
| Benchmark | Weight |
|---|---|
| MATH | 40% |
| GPQA | 25% |
| MMLU | 15% |
| AIME 2025 | 15% |
| ARC | 5% |
Reasoning Intent:
| Benchmark | Weight |
|---|---|
| GPQA | 30% |
| MMLU | 25% |
| MATH | 20% |
| MMLU-Pro | 15% |
| ARC | 10% |
General Intent:
| Benchmark | Weight |
|---|---|
| MMLU | 30% |
| GPQA | 15% |
| HumanEval | 15% |
| MATH | 15% |
| IFEval | 15% |
| HellaSwag | 10% |
Worked Example
Section titled “Worked Example”GPT-4o with Code intent:
Suppose GPT-4o has these benchmark scores: HumanEval = 0.902, MMLU = 0.887. SWE-bench and LiveCodeBench are not available for this model.
| Benchmark | Score | Weight | Contribution |
|---|---|---|---|
| HumanEval | 0.902 | 0.35 | 0.3157 |
| SWE-bench | — | — | skipped |
| LiveCodeBench | — | — | skipped |
| MMLU | 0.887 | 0.10 | 0.0887 |
| IFEval | — | — | skipped |
Sum of contributions: 0.3157 + 0.0887 = 0.4044 Sum of available weights: 0.35 + 0.10 = 0.45
Quality score = 0.4044 / 0.45 = 0.898
Selection and precedence
Section titled “Selection and precedence”Only enabled provider/model pairs in the effective rule’s Smart Cost configuration are candidates. An empty list means no optimization; other catalog models are not discovered automatically.
When Feedback-driven is active, it controls quality, approved targets and the single exploration budget. Smart Cost can break an exact quality tie among approved targets, or contribute external models exclusively in exploration bands. An external model with good feedback remains excluded from exploit until explicitly added to rule targets. See the full decision flow.
Eligibility
Section titled “Eligibility”- Configured tier must match the request’s tier.
- Provider needs a key and catalog support for requested tools/structured output.
- Input/output prices for both candidate and baseline must be known; unknown does not mean free.
- Candidate midpoint token cost must be strictly lower than baseline cost.
- Constraints, confidence and required shadow validation apply, including to untested candidates.
Standalone Smart Cost
Section titled “Standalone Smart Cost”Without active Feedback-driven, the baseline is the declared strategy’s first choice. Tested candidates need at least 10 requests in the 7-day window and quality ≥ min_quality. Quality uses average manual feedback, auto feedback when manual is absent, or benchmarks when feedback is absent; dynamic source weights belong to Feedback-driven.
Exploit ranks candidates with:
score = 0.4 × success_rate + 0.4 × quality + 0.2 × savings_ratioSimple and Moderate use this score in separate configured tier pools. Complex bypasses to the rule strategy; in joint mode, Feedback-driven continues among approved targets.
Exploration without unlimited bootstrap
Section titled “Exploration without unlimited bootstrap”One draw defines explore_untested in [0, r × p), explore in [r × p, r), and exploit in [r, 1). r is total exploration rate and p its reserved untested share. Explore uses tested candidates meeting quality; ExploreUntested uses candidates with fewer than 10 requests and skips only the statistical quality floor. Both use Thompson sampling with HTTP successes and failures.
Zero rate never explores, including cold start. Zero untested share never tests new models. Empty pools fall back to exploit or bypass without reallocating the budget. History failure bypasses optimization; a valid empty history permits trials only in the reserved band. Missing feedback does not enable Smart Cost automatically.
Configuration
Section titled “Configuration”- Go to Routing in the dashboard.
- Create or edit a routing rule.
- Enable Smart Cost Routing.
- Configure the following parameters:
- Exploration Rate: Percentage of requests used for testing less-explored models (default: 10%).
- Minimum Quality: The minimum acceptable quality score for a candidate model (default: 70%).
- Providers: Restrict which providers and models can be used as routing targets.
Monitoring
Section titled “Monitoring”Every response routed through Smart Cost Routing includes headers that tell you what happened:
| Header | Description |
|---|---|
Floopy-Smart-Cost-Decision | Effective decision: exploit, explore, explore_untested, bypass or complex_tier |
Floopy-Model | The model that actually served the request |
Use these headers in your application to log routing decisions, build dashboards, or trigger alerts when routing behavior changes unexpectedly.
Availability
Section titled “Availability”Smart Cost Routing is available on the Pro plan.