How rachitsethi2455/cost-aware-model-router works
Adaptive LLM Router accepts a query through its API, extracts interpretable features, chooses a model tier, calls a provider, and checks small-model answers for deterministic escalation before returning answer and cost metadata. The API also exposes a no-inference explanation route and health/statistics endpoints. Separate evaluation tools train and analyze the router and benchmark routing modes. The graph follows the supplied excerpts, SOURCE INDEX references, and README; unsampled API details and provider registration behavior are not expanded beyond those references.
Main entry points: pipeline.py Routing pipeline · llm.py LLM client · classifier.py Learned router · main.py HTTP API and demo
Components 20
API service
- HTTP API and demo
src/api/main.py
Routing and quality
- Routing pipeline
src/router/pipeline.py - Query features
src/router/features.py - Learned router
src/router/classifier.py - Heuristic router
src/router/heuristic.py - Quality escalation
src/router/escalation.py
Inference and providers
- Model configuration
src/router/config.py - LLM client
src/router/llm.py - Response cache
src/router/cache.py - Provider selection
src/router/providers/__init__.py - Provider interface
src/router/providers/base.py - Anthropic provider
src/router/providers/anthropic_provider.py - OpenAI-compatible provider
src/router/providers/openai_compat.py - Call result and costs
src/router/types.py
Router evaluation
- Router training
evals/train_router.py - Router analysis
evals/analyze_router.py - Pipeline benchmark
evals/run_benchmark.py - Answer judge
evals/judge.py
Other components
- API caller
- Model services
Connections 28
- API caller → HTTP API and demo: submits query
src/api/main.py - HTTP API and demo → Routing pipeline: runs request
src/api/main.py - HTTP API and demo → Learned router: explains route
src/api/main.py - HTTP API and demo → Heuristic router: explains route
src/api/main.py - Routing pipeline → Query features: extracts features
src/router/pipeline.py - Routing pipeline → Learned router: selects tier
src/router/pipeline.py - Routing pipeline → Heuristic router: selects tier
src/router/pipeline.py - Learned router → Query features: extracts features
src/router/classifier.py - Heuristic router → Query features: scores features
src/router/heuristic.py - Routing pipeline → LLM client: calls model
src/router/pipeline.py - Routing pipeline → Quality escalation: checks answer
src/router/pipeline.py - Routing pipeline → Model configuration: selects tier spec
src/router/pipeline.py - LLM client → Response cache: reads and writes
src/router/llm.py - LLM client → Model configuration: uses model settings
src/router/llm.py - LLM client → Provider selection: selects provider
src/router/llm.py - Provider selection → Provider interface: registers providers
src/router/providers/__init__.py - Provider selection → Anthropic provider: registers provider
src/router/providers/__init__.py - Provider selection → OpenAI-compatible provider: registers provider
src/router/providers/__init__.py - Anthropic provider → Model services: sends inference
- OpenAI-compatible provider → Model services: sends inference
src/router/providers/openai_compat.py - LLM client → Call result and costs: creates result
src/router/llm.py - Router training → Learned router: trains model
evals/train_router.py - Router analysis → Learned router: evaluates classifier
evals/analyze_router.py - Router analysis → Heuristic router: evaluates rules
evals/analyze_router.py - Router analysis → Query features: extracts inputs
evals/analyze_router.py - Pipeline benchmark → Routing pipeline: runs routing arms
evals/run_benchmark.py - Pipeline benchmark → Answer judge: grades answers
evals/run_benchmark.py - Answer judge → LLM client: requests grading call
evals/judge.py