KLAW Router
K-104 Intelligent Model Router. Route AI queries to the cheapest model that can handle them. Up to 48x cheaper than Claude Opus — without sacrificing quality.
Install
pip install klaw-router
Quick Start
from klaw import KlawRouter
router = KlawRouter()
result = router.route("How do I center a div?")
print(result["response"]) # The answer
print(result["cost"]) # $0.0001
print(result["savings"]) # $0.0029 saved vs Sonnet baseline
print(result["tier_name"]) # "template" (free)
Pass API keys directly or via environment variables:
router = KlawRouter(api_keys={
"ANTHROPIC_API_KEY": "sk-ant-...",
"OPENAI_API_KEY": "sk-...",
"GEMINI_API_KEY": "AI...",
})
How It Works
Every query gets classified into a K-104 semantic address (4 domains × 13 ranks × 2 polarities = 104 rooms) and routed to the minimum capable model:
| Tier | Models | Cost/query |
|---|---|---|
| 0 — Template | Built-in corpus (1,000+ patterns) | $0.00 |
| 1 — Local | Ollama, OpenRouter free tier | $0.00 |
| 2 — Cheap | Haiku, GPT-4o-mini, Gemini Flash | ~$0.001 |
| 3 — Mid | Sonnet, GPT-4o, Gemini Pro | ~$0.01 |
| 4 — Premium | Opus, GPT-4 | ~$0.05 |
The classifier routes ~80% of everyday queries to tier 0–1 (free). Only genuinely complex reasoning reaches premium tiers.
Empirical result: Transformer activations cluster by K-104 suit with silhouette score 0.312 — the geometry is real, not imposed.
Claude Code MCP Integration
Add to your .mcp.json:
{
"mcpServers": {
"klaw": {
"command": "klaw",
"args": ["mcp"]
}
}
}
Then use klaw_route, klaw_classify, and klaw_stats tools in Claude Code.
CLI
klaw route "What is Python?"
klaw classify "Explain quantum physics"
klaw stats
klaw demo
klaw setup
API Keys
Set via environment variables:
export ANTHROPIC_API_KEY=sk-ant-...
export OPENAI_API_KEY=sk-...
export GEMINI_API_KEY=AI...
export OPENROUTER_API_KEY=sk-or-...
Or pass directly to KlawRouter(api_keys={...}). No keys required for tier 0 template routing.
Classify Only
from klaw import KlawRouter
r = KlawRouter()
c = r.classify("debug this async Python function")
print(c["suit"]) # "spades"
print(c["tier"]) # 2
print(c["k_address"]) # "+5S"
Testing
cd openclaw
pip install pytest
python -m pytest tests/ -v
All 10 tests pass without API keys (template tier is free).
License
MIT
Metadata
Release files for klaw-router 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| klaw_router-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for klaw_router-0.1.2-py3-none-any.whl |
Release files / klaw_router-0.1.2-py3-none-any.whl
| Download URL | klaw_router-0.1.2-py3-none-any.whl |
|---|---|
| Size | 32.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb6105be9efa2ada5154d58492b43187ccaac8b09c1580b9006a504f21acd54b
|
|
BLAKE2b-256 checksum How to use checksums |
36c9705f3283aefc07cd278e6805f1d999c94d4dd560ab154516dc92b1c99dc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for klaw-router 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.