Francis1998/nexus-llm-router
Drop-in LLM router and AI gateway for OpenAI Chat Completions, Responses and Anthropic Messages APIs: 125 routing strategies (incl. feedback-aware Thompson sampling) across GPT-6, Claude Opus 5.5 / Fable 5.2, Gemini 4 and Kimi K3.1, a request feedback API, budgets, fallbacks, tenant rate limits, idempotency and audit logs.
Featured achievements
The project's latest awards
#1 Repository of the week
#2 Repository of the week
#3 Repository of the week
nexus-llm-router
Intelligent multi-LLM routing middleware with task-aware model selection, cost optimization, fallback safety, and a drop-in OpenAI-compatible API.

Why Nexus
Most teams start with one LLM endpoint. That works until traffic grows, latency starts swinging, finance asks why every request hits the most expensive model, and incident review asks why the app kept calling a degraded provider. Nexus gives the application one stable OpenAI-compatible API while moving model choice, fallback, budget, audit, and routing rationale into infra-owned middleware.
Nexus is designed for AI infrastructure engineers running multi-model production pipelines where quality, latency, and cost must be optimized at the same time.
Problems It Solves
-
Issue: every prompt is sent to the same frontier model. Nexus solves this by classifying prompt complexity and routing simple tasks to cheaper low-latency models while reserving premium models for hard prompts.
-
Issue: spend grows faster than product usage. Nexus solves this with cost-aware routing, model cost estimates, per-user budget guardrails, and Prometheus cost metrics.
-
Issue: code, medical, legal, and general prompts need different quality defaults. Nexus solves this by extracting a domain tag and applying deterministic policy rules such as medical/legal to Claude Sonnet 4.6 and complex code to GPT-5.5.
-
Issue: one provider has an incident and the app fails hard. Nexus solves this with per-provider circuit breakers and automatic fallback chains.
-
Issue: provider latency spikes during peak traffic. Nexus solves this with latency-aware routing that tracks rolling p95 latency and penalizes slow providers.
-
Issue: teams want to compare models without rewriting product code. Nexus solves this with stable request-id A/B routing selected by the
X-Router-Strategyheader. -
Issue: support and compliance teams ask why a model answered a request. Nexus solves this by persisting durable audit records with
request_id, selected model, strategy, rationale, latency, token usage, and cost. -
Issue: a single API key can overwhelm the router. Nexus solves this with a token-bucket rate limiter keyed by API key identifier.
-
Issue: session or tenant budgets need hard enforcement. Nexus solves this by rejecting requests before dispatch when estimated spend would exceed the configured cap.
-
Issue: PII can leak into third-party providers. Nexus solves this with optional regex redaction and a Presidio extension path before provider dispatch.
-
Issue: teams need OpenAI compatibility without giving up provider choice. Nexus solves this by exposing
/v1/chat/completionswhile normalizing OpenAI, Anthropic, Gemini, and Moonshot adapters behind one interface. -
Issue: model routing becomes a hidden product decision. Nexus solves this by making routing policy explicit, testable, observable, and owned in infra.
Demo Gallery
Terminal routing demo with JSON rationale logs:

Observe -> Decide -> Act state-machine demo:

Features
- Router engine with configurable strategies
- Adapter pipeline with full observability
- Async-first design using
asyncio+httpx - Type-safe with full
mypycompliance - Production-ready with Docker, CI/CD, and structured logging
Quick Start
git clone https://github.com/Francis1998/nexus-llm-router.git
cd nexus-llm-router
pip install -e ".[dev]"
cp .env.example .env
PYTHONPATH=src uvicorn api.main:app --reload
Quality Gates
ruff check src/ tests/ scripts/
mypy src/
pytest tests/ -v
Docker Compose
docker compose up --build
Services:
- Router:
http://localhost:8000 - Prometheus:
http://localhost:9090 - Grafana:
http://localhost:3000
Routing Strategies
Select a strategy with X-Router-Strategy:
rule-based: domain and complexity priority matrixclassifier: logistic-regression-style complexity and domain featurescost-optimal: minimizes estimated cost subject to quality floorlatency-aware: penalizes providers with poor rolling p95 latencyreliability-aware: routes to the highest-quality model whose provider circuit is closed, and orders the fallback chain healthy-providers-firstweighted-blend: selects the model with the highest tunable composite of normalized quality, cost, and latency (weights viaNEXUS_BLEND_*)budget-aware: selects the highest-quality model whose estimated per-request cost stays within a hard ceiling (NEXUS_REQUEST_COST_CEILING_USD); the dual ofcost-optimalab: deterministic request-id buckets across two model arms
Documentation
| Document | Description |
|---|---|
| Architecture | System design and component overview |
| Configuration | All configuration options |
| Quickstart | Local setup and first request |
| Safety | Guardrails, fallback, and PII controls |
| Contributing | Development workflow and PR process |
| Security | Vulnerability reporting policy |
| Changelog | Version history |
License
Apache-2.0 © Francis1998
Last updated: 2026-06-26
Similar Projects
Discover other similar projects and AI models.
Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
Open-source AI gateway. Self-hosted LLM gateway with OpenAI-, Claude- and Gemini-compatible APIs, model routing, access control, usage tracking and cost accounting.
⚡ Awesome AI Gateway — pick an AI gateway from 240+ (LiteLLM, OpenRouter, Portkey, Kong, Higress, new-api, Bifrost) by cost, security & compliance, see what consolidated in 2026, learn how they actually work from an 8-chapter handbook, and verify every number yourself. Reproducible benchmarks, bilingual; stars & releases refreshed daily.
The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
why use many token when few token do trick. Skill + local proxy for coding agents: shorter answers, smaller tool output, every original recoverable.
Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Leaked system prompts of ChatGPT, Claude, Gemini and more. The hidden system prompt of every popular chatbot, in full, every version since May 2025. Also Anthropic Claude Code, OpenAI Codex, Google Antigravity, xAI Grok, Meta Muse, Moonshot Kimi, Alibaba Qwen, Z.ai GLM ZCode, MiniMax, Cursor, Perplexity, DeepSeek and 30+ others. Updated daily.