doramirdor/NadirClaw: Open-Source LLM Router That Cuts API Costs 40-70%
Running LLM-powered development tools like Claude Code, Cursor, or Codex gets expensive fast. Every prompt hits your most capable model by default—even when a cheaper option would suffice. For teams and solo developers alike, this waste compounds quickly. doramirdor/NadirClaw addresses this directly: it's a self-hosted, drop-in proxy that classifies prompts in ~10ms and routes simple ones to cheap or local models while reserving premium models for genuinely complex requests. The result, according to the project's benchmarks: 40-70% cost reduction with 98.3% quality preserved versus always using a top-tier model.
What is doramirdor/NadirClaw?
doramirdor/NadirClaw is an open-source LLM router and AI cost optimizer written in Python↗ Bright Coding Blog. It functions as a transparent local proxy between your AI-powered tools and the actual LLM providers. Rather than sending every request to your default expensive model, NadirClaw intercepts each prompt, analyzes its complexity, and dispatches it to the cheapest model likely to handle it well—verifying the output and escalating only when necessary.
The project is maintained by doramirdor and has attracted 612 GitHub stars and 73 forks as of its last commit on July 6, 2026. It carries a PolyForm Noncommercial 1.0.0 license for free noncommercial use, with commercial licensing available through the Nadir Pro hosted service. The repository's active development and growing community signal genuine traction among cost-conscious developers.
NadirClaw's relevance stems from a real pattern in LLM usage: per the project's analysis, 60-70% of typical coding session prompts are simple—file reads, short questions, formatting requests, docstring generation. These don't need Claude Sonnet or GPT-5. They work fine on Gemini Flash, Haiku, or even local Ollama models that cost 10-20x less. Without intelligent routing, you're systematically overpaying.
Key Features
~10ms Classification Overhead: NadirClaw uses a lightweight embedding-based classifier (default: binary centroid on sentence-transformer embeddings) that adds negligible latency. An optional DistilBERT classifier (~30ms) or trained checkpoint (~40ms CPU) offers more granularity for users who need it.
Verify-Then-Escalate Architecture: The tool doesn't blindly trust cheap model outputs. A post-generation verifier scores responses against quality heuristics—checking for refusals, truncation, and JSON format failures—before delivery. If the score falls below τ = 0.80, NadirClaw automatically retries with the next tier up. An optional trained DeBERTa cross-encoder verifier (AUROC 0.961 on RouterBench) catches subtler failure modes.
Drop-In OpenAI Compatibility: NadirClaw exposes standard /v1/chat/completions and /v1/messages (Anthropic-compatible) endpoints. Any tool speaking OpenAI's API works without modification—Claude Code, Cursor, Continue, Aider, Windsurf, Codex, OpenClaw, Open WebUI, or custom clients.
N-Tier YAML Configuration: Beyond simple two-tier routing, users can define arbitrary cascade profiles via YAML. The default n2_default.yaml implements a cheap+strong two-tier system tuned on RouterArena (arena_F 0.7358). Custom profiles hot-reload from disk in under 30 seconds.
Context Optimization: The built-in Context Optimize feature compacts bloated payloads—deduplicating repeated tool schemas, minifying JSON, normalizing whitespace—before dispatch. Benchmarked at 61.5% average input token reduction on structured payloads, with modes ranging from lossless (safe) to staged progressive compression.
Local-First, No Middleman: Your API keys never leave your machine. NadirClaw routes directly to providers; there's no third-party proxy that can throttle, inspect, or discontinue service.
Use Cases
Solo Developer Daily Coding with Claude Code: A developer runs claude for 8 hours. Without routing, all 147 requests hit Claude Sonnet at ~$24.18. With NadirClaw, 62% route to Gemini Flash ($1.85), 31% stay on Sonnet ($7.32), 7% go direct for overrides—total $10.29, 57% saved.
Team CI/CD with Autonomous Agents: An OpenClaw-based agent runs 24 hours with mixed tasks. Unrouted: 412 calls to GPT-4.1 at $31.45. With NadirClaw: 68% hit local Ollama (free), 32% stay on GPT-4.1—$11.92 total, 62% saved.
Local-Only Development: Using ollama/llama3.1:8b for simple tier and ollama/qwen3:32b for complex, developers achieve zero API spend entirely. NadirClaw's auto-discovery finds Ollama instances across the local network.
Multi-Provider Resilience: Configure fallback chains like gpt-4.1,claude-sonnet-4-5-20250929,gemini-2.5-flash. When Gemini Flash hits a 429, NadirClaw retries once then cascades to the next model—no failed requests, no manual intervention.
Prompt Testing and Classification Debugging: Run nadirclaw classify "your prompt" to see exactly how any prompt would route, without starting the server. Useful for tuning tier thresholds and validating classifier behavior.
Installation & Setup
NadirClaw supports multiple installation paths. The one-line installer handles dependencies and PATH setup automatically:
curl -fsSL https://raw.githubusercontent.com/doramirdor/NadirClaw/main/install.sh | sh
This clones to ~/.nadirclaw, creates a virtual environment, installs dependencies, and adds nadirclaw to your PATH. Re-run to update.
For manual installation from source:
git clone https://github.com/doramirdor/NadirClaw.git
cd NadirClaw
python3 -m venv venv
source venv/bin/activate
pip install -e .
After installation, run the interactive setup wizard:
nadirclaw setup
This guides you through provider selection, API key entry, and model assignment per tier. Then start the router:
nadirclaw serve --verbose
The server starts on http://localhost:8856 with sensible defaults: Gemini 3 Flash for simple, OpenAI Codex for complex. If you skip nadirclaw setup, serve offers to run it on first launch.
For Docker↗ Bright Coding Blog with fully local Ollama:
git clone https://github.com/doramirdor/NadirClaw.git && cd NadirClaw
docker compose up
This starts Ollama and NadirClaw on port 8856. Pull a model once running:
docker compose exec ollama ollama pull llama3.1:8b
For standalone Docker without Ollama, create a .env from .env.example with your API keys, then:
docker build -t nadirclaw .
docker run -p 8856:8856 --env-file .env nadirclaw
Real Code Examples
Basic curl with auto-routing:
curl http://localhost:8856/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "What is 2+2?"}]
}'
NadirClaw classifies this as simple (~0.2848 confidence) and routes to your configured cheap model—Gemini Flash by default. No model specified; the router decides.
Streaming request:
curl http://localhost:8856/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "What is 2+2?"}],
"stream": true
}'
Full SSE streaming compatible with OpenClaw, Codex, and other streaming clients. The classification overhead (~10ms) occurs before streaming begins.
Python client usage:
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8856/v1",
api_key="local", # NadirClaw doesn't require auth by default
)
response = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "What is 2+2?"}],
)
print(response.choices[0].message.content)
The auto model triggers per-prompt classification. You can also force profiles: eco (always cheap), premium (always complex), reasoning (reasoning-optimized model), or free (local fallback).
Testing classification without the server:
$ nadirclaw classify "Design a distributed system for real-time trading"
Tier: complex
Confidence: 0.1843
Score: 1.0000
Model: gemini-2.5-pro
Machine-readable JSON output for scripting: nadirclaw classify --format json <prompt>.
Claude Code seamless integration:
nadirclaw claude onboard --interactive
This detects your Claude Code models, maps them to NadirClaw tiers, persists ANTHROPIC_BASE_URL and ANTHROPIC_MODEL to ~/.claude/settings.json, and installs a launchd/systemd auto-start unit. Afterward, claude from any shell routes through NadirClaw transparently.
Advanced Usage & Best Practices
Configure tier thresholds for your workload: The default NADIRCLAW_TIER_THRESHOLDS=0.35,0.65 works for general coding, but adjust if you see misrouting. Lower the simple_max threshold to send more prompts cheap; raise complex_min to be more conservative with premium model usage.
Enable context optimization for agentic workflows: If your tool sends repeated system prompts with large tool schemas, start with --optimize safe (lossless). Measure actual savings with nadirclaw optimize <file> before enabling server-wide. Aggressive mode risks semantic loss; progressive mode stages compression until a token budget is met.
Monitor with built-in tools: Use nadirclaw report --by-model --by-day for cost breakdowns, nadirclaw savings for running totals, and nadirclaw dashboard for real-time terminal monitoring. The web dashboard at http://localhost:8856/dashboard provides richer visualization.
Set rate limits per model: Prevent runaway costs with NADIRCLAW_MODEL_RATE_LIMITS=gemini-3-flash-preview=30,gpt-4.1=60. When limits hit, fallbacks trigger automatically.
Use session persistence intentionally: The 30-minute TTL on model pinning prevents jarring mid-conversation switches, but for truly stateless use cases, you may want shorter TTLs via configuration.
Comparison with Alternatives
| Feature | doramirdor/NadirClaw | LiteLLM Proxy | NotDiamond |
|---|---|---|---|
| Hosting | Self-hosted (local) | Self-hosted or cloud | Cloud-only |
| Classification | ~10ms local embedding | Manual model selection | Cloud API call |
| Verification | Built-in heuristic + optional trained verifier | None | Proprietary |
| Cost | Free (noncommercial) | Open-source (MIT) | Usage-based pricing |
| Key handling | Your keys, your machine | Your keys | Their proxy |
| Fallback chains | Configurable N-tier | Basic fallback | Unknown |
| Context optimization | Built-in, pluggable backends | None | Unknown |
LiteLLM Proxy excels at unified provider access and load balancing but lacks intelligent prompt classification—you still manually specify models per request. NotDiamond offers routing intelligence but requires sending prompts to their cloud service, introducing latency, cost per classification, and trust assumptions. NadirClaw's trade-off: you run it yourself, with classification happening locally and verification before escalation. For teams wanting managed service with retraining, Nadir Pro (the hosted commercial tier) adds a trained classifier, live dashboard, team billing, and SSO.
FAQ
Does NadirClaw work with my existing API keys? Yes. It uses your keys directly; no separate account or token purchase needed.
What Python version is required? Python 3.10 or newer.
Can I use it commercially? The open-source release is PolyForm Noncommercial 1.0.0. Commercial use requires a license via getnadir.com.
How much does classification add to latency? ~10ms for the default binary centroid; ~30-40ms for optional neural classifiers.
What if the cheap model gives a wrong answer? The verifier catches obvious failures (refusal, truncation, bad JSON) and escalates. The 1.7% catastrophic-downgrade rate on RouterBench means most errors are caught; subtle factual errors may slip through heuristic verification.
Does it support local models only? No. Mix local (Ollama) and cloud (OpenAI, Anthropic, Gemini, DeepSeek, etc.) freely per tier.
How do I update model pricing or add custom models? Use nadirclaw update-models for registry refreshes, or add private entries to ~/.nadirclaw/models.local.json.
Conclusion
doramirdor/NadirClaw fills a specific, well-defined need: intelligent LLM routing that materially reduces API spend without sacrificing workflow quality. Its ~10ms classification, verify-then-escalate design, and genuine drop-in compatibility make it practical for daily use rather than a promising prototype. The 40-70% cost savings claim is benchmarked, not aspirational—though your actual results depend on prompt mix and model choices.
It's best suited for solo developers and small teams running AI-assisted coding tools regularly, self-hosters who prioritize key control, and cost-conscious organizations willing to trade a small local service for ongoing savings. Teams needing managed infrastructure, team features, or adaptive retraining should evaluate Nadir Pro.
Ready to stop overpaying for simple prompts? Explore the repository, run the one-line installer, and start routing smarter.