Llm Router

data-ai MCP Server

Universal LLM router for AI coding tools. Works with Claude Code, Cursor, Codex, Gemini CLI, Copilot and more. Free-first fallback chain keeps costs 70–85% lower.

data-aidata-ai
3 views31 stars5 forksMIT

Why This Matters

Discovered via unknown and last synced 3mo ago.

Source
unknown
Stars
31
Last synced
3mo ago
Install
Check source

Install

Install instructions not detected yet

Check the source repository for the latest setup steps.

View source instructions
40
Tools
0
Resources
0
Prompts
Standard I/O
Transport

Available Tools (40)

full

ultra) ``` ### Config File (Enterprise) For teams with security policies blocking `.env` files: ```bash # Create secure config file llm-router init-config # Edit ~/.llm-router/config.yaml openai_api_key: "sk-proj-..." gemini_api_key: "AIza..." ollama_base_url: "http://localhost:11434" llm_router_profile: "balanced" ``` Set permissions: `chmod 600 ~/.llm-router/config.yaml` For full setup guide, see **[docs/SETUP.md](docs/SETUP.md)**. --- ## Monitoring & Optimization ### Real-Time Session Metrics ```bash # Show savings from current session llm-router usage today # Show all usage data (weekly breakdown) llm-router usage week # Show cost efficiency over time llm-router savings # Check current quota pressure llm-router budget ``` ### Identify Optimization Opportunities ```bash # Analyze routing decisions and find inefficiencies python3 scripts/analyze-violations.py # → Shows which sessions violated routing hints # → Identifies patterns (e.g., Bash used when llm_query should route) # Analyze hook health llm-router health # → Model quality scores, provider status, circuit breaker state ``` ### Preventing Routing Violations **Violation:** Ignoring a `⚡ MANDATORY ROUTE` hint (costs extra tokens with zero savings). **Example violation:** ``` ⚡ MANDATORY ROUTE: query/simple → call llm_query ❌ User/Claude uses Bash instead → burns expensive Claude tokens ``` **Enforcement modes:** ```bash LLM_ROUTER_ENFORCE=smart # (default) Hard block Q&A violations, soft block code LLM_ROUTER_ENFORCE=hard # Block all violations (strictest, best savings) LLM_ROUTER_ENFORCE=soft # Log violations, allow calls (permissive) LLM_ROUTER_ENFORCE=off # No enforcement (max flexibility) ``` **Sessions with 3+ violations** get a warning: ``` ⚠️ ESCALATION: 5 routing violations this session. Next prompt should call llm_query FIRST before any Bash/Read/Edit. Set LLM_ROUTER_ENFORCE=hard to block violations automatically. ``` For detailed guidance, see **[Monitoring & Reducing Violations](README.md#monitoring--optimization)** in CLAUDE.md. --- ## What's New in Recent Releases ### v7.6.0 — Agent Resource Budgeting (Latest) **Complete budget management for Agent calls with provisional tracking.** - **Session Budget Allocation** — Smart carving: 30% of remaining quota per session, $5–$50 range - **Provisional Spend Tracking** — Real-time budget decrements prevent multiple agents from thinking budget is available - **Budget Reconciliation** — On failure: refund 50% (only pay for delivered value) - **Hard Limits** — $5/agent, $50/session (fallback safety valve) Example: ``` Session → $5 budget allocated Agent 1 (code) → -$1.00 → $4 remaining Agent 2 (code) → -$1.00 → $3 remaining Agent 1 succeeds → keep deduction Agent 2 times out → refund $0.50 → $3.50 remaining ``` See [Agent Resource Budgeting](CLAUDE.md#agent-resource-budgeting) for detailed setup. ### v7.4.0 — Content Generation Routing Discipline **Automatic detection of writing tasks with decomposition guidance.** - **Smart Detection** — Recognizes "write", "draft", "add card", "create spec" patterns - **Decomposition** — Suggests: route generation → integrate locally (saves 90% on writing) - **Soft Nudges** — Hook suggests routing without blocking Example suggestion: ``` ⚡ SUGGESTION: This looks like content generation. Consider: llm_generate() first, then Edit/Write to integrate. Saves ~$0.0005, follows best-practice decomposition. ``` ### v7.0.0 — Free-First Chain & Ollama Auto-Startup **Optimized routing chains with automatic local inference.** - **Ollama Auto-Startup** — Session-start hook launches Ollama + loads budget models if not running - **Free-First Chains** — Ollama → Codex → Gemini → OpenAI → Claude (all complexity levels) - **Codex as Free Fallback** — Injected before all paid models when subscription available - **Routing Analytics** — Track which model selected, cost impact, complexity distribution See [CHANGELOG.md](CHANGELOG.md) for complete v6.x history. --- ## MCP Tools Reference (48 Total) ### Routing & Classification

soft

off export LLM_ROUTER_MAX_AGENT_DEPTH=3 # Circuit breaker for nested agents # Advanced export LLM_ROUTER_DB_PATH="~/.llm-router/usage.db" # Where to store usage logs export LLM_ROUTER_CAVEMAN_INTENSITY="full" # Compress output tokens (off

llm_analyze

Deep analysis (Sonnet-class reasoning)

llm_pipeline_templates

List available pipeline templates

llm_setup

Interactive provider setup guide

llm_auto

Host-agnostic routing wrapper (savings tracking)

llm_track_usage

Manually log token usage for budget tracking

llm_image

Generate images (Gemini/DALL-E/Flux)

llm_budget

Real-time budget pressure (0.0–1.0)

llm_check_usage

Refresh Claude subscription quota data

llm_fs_edit_many

Multi-file edits with cheap model reasoning

llm_video

Generate videos (Gemini Veo/Runway)

llm_health

Provider health status & circuit breaker state

llm_update_usage

Update usage cache from API response

llm_fs_analyze_context

Build workspace context for routing

llm_route

Route task to optimal model by complexity/profile

llm_edit

Multi-file code edits with reasoning

llm_usage

Show cost breakdown (today/week/month/all)

llm_quality_report

Judge scores & quality trends

llm_fs_find

Find files by description

llm_classify

Classify task complexity: simple/moderate/complex

llm_savings

Cost savings vs Opus baseline

llm_save_session

Archive session for cross-session learning

llm_fs_rename

Generate bulk rename commands

Tool

Purpose

llm_research

Research with web access (Perplexity)

llm_set_profile

Switch routing profile (budget/balanced/premium)

Static

No personalization

balanced

premium export LLM_ROUTER_ENFORCE="smart" # smart

llm_generate

Create content (Flash-class, cheap)

llm_orchestrate

Multi-step pipelines (research → analysis → generation)

llm_codex

Route directly to Codex (prepaid OpenAI subscription)

llm_query

Answer questions (Haiku-class models, fast)

llm_audio

Generate speech (ElevenLabs/OpenAI TTS)

llm_providers

List configured providers & API key status

llm_refresh_claude_usage

Auto-refresh Claude quota (OAuth)

Aspect

llm-router

llm_code

Code generation & refactoring (Sonnet → Opus)

llm_policy

View/manage routing policies

llm_gemini

Route directly to Gemini CLI