Complexity-aware LLM routing proxy: classify, cascade, orchestrate.
Project description
FluxRouter
Dynamic, complexity-aware LLM routing layer
Classifies queries by complexity to dynamically dispatch fast or strong models; optimizing cost and latency without sacrificing response quality.
Why FluxRouter?
Routing every prompt to a frontier model like qwen-27b or llama-70b is wildly expensive, 70% of production LLM queries (simple facts, basic syntax checks, short summaries) can be answered flawlessly by lightweight 8B models at 1/10th the cost.
Conversely, locking your application to a small fast model leads to hallucinations and incomplete reasoning on difficult architectural, algorithmic, or debugging prompts.
FluxRouter solves this dilemma with Cascade Routing:
- Ultra-fast Classification (5ms): Embeds the query on CPU using
all-MiniLM-L6-v2and classifies complexity intosimple,medium, orcomplexvia k-NN anchor matching. - Direct High-Margin Routing: Confident simple queries bypass LLM judging entirely to hit the fast model (
llama-3.1-8b-instant); complex queries route directly to the strong model (qwen/qwen3.6-27b). - Smart LLM-As-Judge Cascade: Borderline queries invoke a lightweight LLM judge on the fast model's response. If the response score is $\le 3/5$, FluxRouter automatically escalates to the strong model.
Architecture Overview
┌──────────────────────────┐
│ Incoming User Query │
└────────────┬─────────────┘
│
▼
┌──────────────────────────┐
│ ComplexityClassifier │
│ (MiniLM L2 + k-NN) │
└────────────┬─────────────┘
│
┌──────────────────────────┼──────────────────────────┐
│ (Simple & Margin ≥ 0.04) │ (Complex & Margin ≥ 0.04)│ (Medium / Low Margin)
▼ ▼ ▼
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Fast Model │ │ Strong Model │ │ Fast Model │
│ llama-3.1-8b-inst│ │ qwen/qwen3.6-27b│ │ (Initial Attempt)│
└──────────────────┘ └──────────────────┘ └─────────┬────────┘
│
▼
┌──────────────────┐
│ Fast LLM Judge │
└─────────┬────────┘
│
┌─────────────────────┴─────────────────────┐
│ Judge Score ≥ 4/5 │ Judge Score ≤ 3/5 │
▼ ▼ ▼
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Keep Fast Resp │ │ Escalate Query │ │ Strong Model │
│ (judge_passed) │ │ (judge_escalate) │ │ qwen/qwen3.6-27b│
└──────────────────┘ └──────────────────┘ └──────────────────┘
Web Dashboard
Benchmark Results
Evaluated on a stratified benchmark of 30 representative queries across coding, system architecture, debugging, summarization, and general QA (blind LLM-as-judge scoring 1–5):
| Configuration | Queries | Total Cost ($) | Cost / Query ($) | Avg Latency | Mean Quality | Strong Usage Rate | Cascade Escalation Rate | Fast Calls | Strong Calls |
|---|---|---|---|---|---|---|---|---|---|
always_fast |
30 | $0.00226 | $0.000075 | 1,754 ms | 4.77 / 5 | 0.0% | n/a | 30 | 0 |
always_strong |
12 | $0.01064 | $0.000887 | 3,104 ms | 5.00 / 5 | 100.0% | n/a | 0 | 12 |
fluxrouter |
30 | $0.01006 | $0.000335 | 3,735 ms | 4.90 / 5 | 26.7% | 3.3% | 22 | 8 |
Per-Query Comparison Highlights
- FluxRouter vs
always_strong: Substantial cost reduction per query ($0.000335 vs $0.000887 average) while maintaining 4.90 / 5 mean response quality (a negligible quality delta of -0.10/5). - Strong Model Usage vs. Escalation Rate: 26.7% Total Strong Model Usage (8/30 queries used the strong model). 7 queries were classified as
complexand routed directly to the strong model, while 1 query was escalated via the cascade evaluation mechanism (3.3% cascade escalation rate). - FluxRouter vs
always_fast: +0.13 / 5 Quality Gain over fast-only models by routing complex multi-step and architectural prompts to the strong model.
Known Limitations & Design Considerations
- Medium Tier Fuzziness:
The medium complexity band is inherently continuous. Prompts on the boundary between simple and medium may occasionally be routed directly to the fast model if the classifier margin exceeds
0.04. - Escalation Sensitivity:
Fast models (
llama-3.1-8b-instant) are surprisingly capable on structured coding tasks, scoring $\ge 4/5$ on many medium queries. Consequently, escalation to the strong model only triggers when the fast response is incomplete, truncated, or erroneous. - Model Selection Rationale (
qwen/qwen3.6-27b):qwen/qwen3.6-27bis configured as the default strong model overllama-3.3-70b-versatile. On Groq's free/on-demand tier,llama-3.3-70b-versatilehas a 100,000 Tokens-Per-Day (TPD) quota limit.qwen/qwen3.6-27bprovides a 500,000 TPD daily quota while matching 70B-class reasoning quality.
Installation & Quickstart
# 1. Install in editable mode
git clone https://github.com/sid-stack001/FluxRouter.git
cd fluxrouter
pip install -e .
# 2. Interactive setup: configures Groq API key and defaults in ~/.fluxrouter/config.yaml
fluxrouter init
# 3. Route your first prompt
fluxrouter route "What is the capital of France?"
Integration Paths
1. Command Line Interface (CLI)
# Direct routing with Rich terminal formatting
fluxrouter route "Explain the CAP theorem in distributed systems"
# Raw JSON output for pipeline automation
fluxrouter route "Write a Python function to merge two sorted lists" --json
# Agent task orchestration (decompose → route subtasks → synthesize)
fluxrouter agent "Write a Python function to reverse a string, add docstrings, and write unit tests"
# Interactive configuration manager
fluxrouter config --show
2. OpenAI-Compatible API Proxy Server
Exposes an OpenAI-compatible /v1/chat/completions endpoint, so it can be used as a drop-in backend anywhere you'd normally point the standard openai SDK, including most agent frameworks that support custom OpenAI-compatible base URLs (e.g. LangChain, AutoGen). Tested directly with the openai Python SDK; framework-specific integration not yet verified.
fluxrouter serve --port 8000
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="none", # Auth handled by FluxRouter
)
response = client.chat.completions.create(
model="fluxrouter", # Dynamic complexity routing
messages=[{"role": "user", "content": "Architect a real-time collaborative editor."}]
)
print(response.choices[0].message.content)
3. Native Python SDK (In-Process)
from fluxrouter import FluxRouter
# Automatically loads configuration from ~/.fluxrouter/config.yaml
router = FluxRouter()
# In-process routing with zero HTTP overhead
decision = router.route("Derive the backpropagation equations for a conv layer.")
print(f"Tier: {decision.predicted_tier} | Escalated: {decision.escalated}")
print(decision.final_response.text)
Roadmap
- Multi-Provider Adapters: native support for Anthropic, OpenAI, and local Ollama models, using the existing (currently Groq-only) adapter pattern.
- Semantic Query Caching: Redis-backed vector cache to serve identical/similar historical queries instantly at zero model cost.
- Circuit Breaker & Failover: Automatic health monitoring and instant failover to secondary model providers on API rate limits (HTTP 429).
- Rich TUI Dashboard: Real-time interactive terminal dashboard tracking live token cost, request rate, and tier distribution.
- Daemon Mode & Multi-Tenant Support: Background service deployment with multi-tenant API key management.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fluxrouter-0.1.1.tar.gz.
File metadata
- Download URL: fluxrouter-0.1.1.tar.gz
- Upload date:
- Size: 497.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbaab8cff92f9d710836bec7b3b6560c505fc1a7a910f8d29ec7574b3d2fa01f
|
|
| MD5 |
98d65879ed71cd833be59e0e6a5ede2b
|
|
| BLAKE2b-256 |
71e7d4b9a4e50170b173fbcfecb63d19bc82c3acad477560ad00ddee5599a890
|
File details
Details for the file fluxrouter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: fluxrouter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 57.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b84b4333c8998f8808d9da8b4d21c9bbb2b80823282f0d63ce2b718f021f0931
|
|
| MD5 |
f88f882e169c9421933cf4431d37a54a
|
|
| BLAKE2b-256 |
cce6423f96eacd5a6344fee967e29385589d06840ae5682b15da4b8c8ccdb93f
|