RepositoryPython
Francis1998

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.

122stars
35forks
8issues
1views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: multi-llm

#1 Repository of the week

2
TINIX TRENDING·Topic: llm-router

#2 Repository of the week

3
TINIX TRENDING·Topic: cost-optimization

#3 Repository of the week

nexus-llm-router

Tests Python CI

Intelligent multi-LLM routing middleware with task-aware model selection, cost optimization, fallback safety, and a drop-in OpenAI-compatible API.

Nexus use cases

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-Strategy header.

  • 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/completions while 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.

Terminal routing demo with JSON rationale logs:

Nexus terminal demo

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

Nexus decision flow

Features

  • Router engine with configurable strategies
  • Adapter pipeline with full observability
  • Async-first design using asyncio + httpx
  • Type-safe with full mypy compliance
  • 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 matrix
  • classifier: logistic-regression-style complexity and domain features
  • cost-optimal: minimizes estimated cost subject to quality floor
  • latency-aware: penalizes providers with poor rolling p95 latency
  • reliability-aware: routes to the highest-quality model whose provider circuit is closed, and orders the fallback chain healthy-providers-first
  • weighted-blend: selects the model with the highest tunable composite of normalized quality, cost, and latency (weights via NEXUS_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 of cost-optimal
  • ab: deterministic request-id buckets across two model arms

Documentation

DocumentDescription
ArchitectureSystem design and component overview
ConfigurationAll configuration options
QuickstartLocal setup and first request
SafetyGuardrails, fallback, and PII controls
ContributingDevelopment workflow and PR process
SecurityVulnerability reporting policy
ChangelogVersion history

License

Apache-2.0 © Francis1998

Last updated: 2026-06-26

Similar Projects

Discover other similar projects and AI models.

RepositoryPython
NousResearch/hermes-agent

The agent that grows with you

267.7k
Dec 2, 2026
RepositoryTypeScript
cheaper-inference/OmniRoute

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

91.8k
Dec 2, 2026
RepositoryGo
QuantumNous/new-api

Open-source AI gateway. Self-hosted LLM gateway with OpenAI-, Claude- and Gemini-compatible APIs, model routing, access control, usage tracking and cost accounting.

52.7k
Nov 27, 2026
RepositoryHTML
cuihuan/awesome-ai-gateway

⚡ 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.

161
Nov 26, 2026
RepositoryJavaScript
affaan-m/ECC

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

315.1k
Dec 1, 2026
RepositoryPython
Significant-Gravitas/AutoGPT

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.

188.2k
Nov 29, 2026
RepositoryGo
JuliusBrussee/caveman

why use many token when few token do trick. Skill + local proxy for coding agents: shorter answers, smaller tool output, every original recoverable.

124.4k
Dec 1, 2026
RepositoryPython
headroomlabs-ai/headroom

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.

81.4k
Dec 2, 2026
RepositoryPython
asgeirtj/system_prompts_leaks

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.

73.9k
Nov 29, 2026