ypollak2/llm-router
Hook- and MCP-based LLM routing for coding tools, with free and local models first
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
llm-router is a Python routing engine with host lifecycle hooks, an MCP server, and an in-process SDK. On hosts with prompt hooks, a regex heuristic assigns a route when it has enough signal and uses the default otherwise. An eligible prompt can go to a free or local model for a draft before escalating through the provider chain. The draft is an unverified hint by default, not a replacement for the host model's turn. The project’s grounding check rejects drafts that cite files or functions absent from both the available context and the indexed repository.
Routing and enforcement are separate: the default smart mode can hold selected tool calls until routing completes, while LLM_ROUTER_ENFORCE=off removes that gate. MCP clients get 12 tools by default, with the consolidated surface defined in src/llm_router/tool_surface.py. Python callers can use Router.run or Router.arun without a separate server. This distinction matters when selecting a host: Pi is MCP-only, and the Copilot extension in VS Code adds capabilities but does not perform cost routing.
Key Capabilities & Differentiators
Ollama, OpenRouter, Gemini, and Groq are among the available backends. YAML policies range from conservative through balanced (the default) to cost_aggressive. Circuit breakers skip failing or rate-limited providers, and the Python SDK can enforce a dollar budget. Beyond text, the tool surface includes image, video, and audio calls and a multi-step orchestration tool. Session summaries report provider cost, tier mix, and p50/p95/p99 latency. The measured heuristic confidently classified 788 of 1,571 prompts in one run; that is coverage, not classification accuracy or acceptance rate.
On covered routes such as the text router, gateway, and streaming, a detected secret sends the request directly to loopback Ollama or causes a refusal. The protected path bypasses the HTTP proxy, semantic cache, judge queue, and cloud fallback; a cloud: prefix can override the decision for one request. This is entrypoint-specific, not a system-wide data-loss prevention control. The Claude Code proxy logs detections without enforcing this rule, and opt-in cloud classifiers and some direct-execution paths are also outside it.
Trade-offs & Limitations
A conventional provider API proxy is simpler when the host already sends API-key traffic to a configurable endpoint and only needs model selection and failover. llm-router is more useful when a subscription workflow can use host hooks or MCP, but host capabilities vary and a draft can add latency without avoiding the premium turn. Savings reports compare actual spend with a counterfactual at API list prices, separating verified from unverified estimates and showing their sample counts. They do not measure cash saved on a flat subscription. RouterArena results were graded with the project's own harness and have not been independently verified.
The most consequential workstation default is direct execution: a local model can write or edit files and run commands. Path rules and static command checks are not an OS sandbox. For an initial rollout, disable this via LLM_ROUTER_DIRECT_EXECUTION=false unless you have reviewed the execution boundary. MIT licensing allows commercial use, but the local deployment does not itself supply organization-wide policy enforcement, SSO, or per-organization budgets.
Hardware & Deployment Guide
Use Python 3.11+ and install the llm-routing package. Run llm-router install for Claude Code or select a host with --host, then use llm-router doctor to check setup and llm-router status to see whether requests are being routed. The subscription-plus-local path does not require additional provider API keys; adding cloud credentials expands the provider pool. The router runs on the workstation, but cloud routes still require network access. Daily KPI scheduling requires consent.
The documented setup-local path for a Mac with at least 48 GB of RAM is opt-in; it downloads about 22 GB and keeps about 22 GB loaded in memory. The separate install --proxy-default step points Claude Code at the proxy with the local model. v16.1.2 added ownership checks for the 127.0.0.1:11435 listener around setup. v16.1.3 sets OLLAMA_NUM_PARALLEL=1 and OLLAMA_CONTEXT_LENGTH=131072 for launchd and systemd services to avoid multiplying KV-cache memory across parallel slots. The v16.1.1 loopback forward proxy for Claude Code Remote Control remains a beta, opt-in path.
Individual developers and small teams that want to test free or local drafts for routine coding prompts, or add budgeted routing to a Python agent without deploying a separate service.
You need identical behavior across IDEs, guaranteed subscription savings, or an organization-wide gateway with mandatory data controls and centrally enforced budgets.
Quick Start & Installation
pip install llm-routing # installs the `llm-router` command
llm-router install # wire up Claude Code (default host)
llm-router doctor # check provider connectivity and setup
llm-router status # verify it's routing — est. savings vs baselineComparison vs. Top Coding, Skills & MCP Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| llm-router ★ | 134 | +3 | Python | MIT | Hook- and MCP-based LLM routing for coding tools, with free and local models fir |
| gemini-cli | 109.6k | +376 | TypeScript | Apache-2.0 | A Node.js terminal agent for enterprise Gemini coding workflows and MCP tools |
| oh-my-pi | 40.5k | +483 | TypeScript | MIT | A Bun/Rust terminal agent for model-flexible coding with LSP and editor integrat |
| aider | 50.3k | +78 | Python | Apache-2.0 | A Git-integrated terminal CLI for editing code with cloud or local models. |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/ypollak2/llm-router.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about llm-router
Does installing the MCP server make it intercept and replace every model turn?
Do I need 48 GB of RAM or a dedicated GPU to use the router?
Can we self-host it commercially, and does that keep our code on-device?
When is this a better fit than a conventional API routing proxy?
Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy