An LLM routing for XiaoO
| Files | Last commit | Last update |
|---|---|---|
| 4 months ago | ||
| 4 months ago | ||
| 4 months ago | ||
| 4 months ago | ||
| 4 months ago | ||
| 4 months ago | ||
| 4 months ago | ||
| 4 months ago | ||
| 4 months ago |
xiaoo-router
OpenAI-compatible cost-saving LLM router for XiaoO. Sits between XiaoO and real LLM providers, routes requests by complexity, caches semantically-close answers, and tracks savings in a dashboard.
Quickstart
1. Router
cd router
cp .env.example .env
# Fill in at least OPENAI_API_KEY (or ANTHROPIC_API_KEY / GROQ_API_KEY)
# and set ROUTER_API_KEY to a secret value.
uv sync
uv run xiaoo-router migrate
uv run xiaoo-router serve --port 9000
2. Dashboard
cd ../dashboard
npm install
NEXT_PUBLIC_ROUTER_BASE=http://localhost:9000 npm run dev
# Open http://localhost:3000, enter your ROUTER_API_KEY in Settings.
3. Test with curl
curl http://localhost:9000/v1/chat/completions \
-H "Authorization: Bearer $ROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "What is 2+2?"}],
"stream": false
}'
4. Configure XiaoO
In ~/.config/xiaoo/config.toml:
[llm]
provider = "openai-compatible"
api_base = "http://127.0.0.1:9000" # no /v1 suffix
api_key_env = "ROUTER_API_KEY"
model = "auto"
XiaoO's URL-fallback will probe POST /, /v1, /chat/completions before
finding /v1/chat/completions — all probe URLs return 404 as required.
5. Run benchmarks
cd benchmarks
pip install httpx
python run_benchmark.py scenarios/qa_chat.jsonl \
--router-base http://localhost:9000 \
--api-key $ROUTER_API_KEY
Architecture
XiaoO ──HTTP──> router (FastAPI :9000)
│
├── classifier (heuristic complexity)
├── semantic cache (embeddings + cosine)
├── policy engine (YAML rules)
└── litellm.acompletion() ──> upstream provider
router ──writes──> SQLite (calls, savings)
router ──exposes──> /metrics (Prometheus)
dashboard (Next.js :3000) ──reads──> router REST API
Tests
cd router
uv run pytest tests/
Docker
cd infra/docker
docker compose up --build
Project layout
router/ — Python FastAPI router
dashboard/ — Next.js 14 dashboard with shadcn/ui
infra/ — Docker Compose, Prometheus & Grafana configs
benchmarks/ — repeatable cost-comparison scenarios
docs/ — architecture, integration, changelog