Route smarter, scale faster
Next-generation AI API router and load balancer with intelligent routing, format transformation, session-aware routing, and zero-config deployment.
AI API
-
π§ SmartRouter - Intelligent Routing - Route requests based on content analysis
- 7 routing condition types: token threshold, keywords, regex, tools, images, custom functions
- Priority-based rule matching with automatic fallback
-
π Transformers - Format Conversion - Seamless API format transformation
- Bidirectional conversion between Anthropic β OpenAI formats
- Tool calls and image content conversion
- Extensible transformer architecture
-
π Distributed Tracing - Request tracing and performance analysis β NEW
- W3C Trace Context compatible
- Span lifecycle management
- Performance bottleneck identification
-
π Prometheus Metrics - Production-grade observability β NEW
- 20+ default metrics (requests, tokens, latency, errors)
- Custom labels and dimensions
- Grafana-ready dashboards
-
π i18n Support - Multi-language interface β NEW
- English and Chinese (Simplified) support
- Runtime language switching
- Parameter interpolation
-
π§ͺ 100% Test Coverage - Comprehensive test suite β NEW
- 89 unit tests across all core modules
- Load balancer, metrics, i18n, routing tests
- CI/CD pipeline with automated testing
-
π Intelligent Load Balancing - 4 strategies: Priority, Round Robin, Weighted, Least Used
- Binary search optimization for weighted strategy (O(log n))
- LRU cache with TTL support
-
π― Session-Aware Routing - 5-hour session persistence for context continuity
- Automatic session cleanup
- Cache statistics and monitoring
-
π‘οΈ Circuit Breaker - Automatic failure detection and recovery
- Configurable threshold and timeout
- Automatic recovery on success
-
π Real-time Dashboard - Modern React 19 + Tailwind CSS 4 UI
- Live metrics and statistics
- Channel management CRUD
- Interactive CLI model selector
-
π OAuth Support - PKCE flow with automatic token refresh
-
π Zero-Config Deployment - One-click deploy to free platforms
-
πΎ SQLite Backend - Lightweight, fast, no external dependencies
- WAL mode for better concurrency
- Automatic migrations
-
π Analytics - Token usage tracking and cost estimation
- Request/response logging
- Tee Stream for data replication
# Install Bun if not already installed / Bun
curl -fsSL https://bun.sh/install | bash
# Clone the repository
git clone https://github.com/dctx-team/Routex.git
cd Routex
# Install dependencies
bun install
# Start the server
bun startOn first run, Routex will guide you through a 3-step setup wizard: Routex 3
-
Add your first AI channel (Anthropic Claude, OpenAI, etc.) AI Anthropic ClaudeOpenAI
-
Configure load balancing strategy
-
Set up dashboard access credentials
Route long-context requests to Gemini automatically: Gemini
curl -X POST http://localhost:3000/api/routing/rules \
-H "Content-Type: application/json" \
-d '{
"name": "Long Context to Gemini",
"type": "longContext",
"condition": {
"tokenThreshold": 60000
},
"targetChannel": "gemini-channel",
"targetModel": "gemini-2.5-pro",
"priority": 100
}'Route code review tasks to Claude Opus: Claude Opus
curl -X POST http://localhost:3000/api/routing/rules \
-H "Content-Type: application/json" \
-d '{
"name": "Code Review Tasks",
"type": "custom",
"condition": {
"keywords": ["code review", "review this code", "analyze code"]
},
"targetChannel": "claude-opus-channel",
"priority": 90
}'Use OpenRouter with automatic format conversion: OpenRouter
curl -X POST http://localhost:3000/api/channels \
-H "Content-Type: application/json" \
-d '{
"name": "OpenRouter Channel",
"type": "openai",
"baseUrl": "https://openrouter.ai/api/v1/chat/completions",
"apiKey": "sk-or-xxx",
"models": ["anthropic/claude-opus-4"],
"transformers": {
"use": ["openai"]
}
}'curl -X POST http://localhost:3000/api/transformers/test \
-H "Content-Type: application/json" \
-d '{
"transformer": "openai",
"direction": "request",
"request": {
"model": "claude-opus-4",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 100
}
}'- π― API Reference
- πΊοΈ Development Roadmap
- βοΈ Configuration Guide
- π Environment Variables
- π Deployment Guide
- π οΈ Function Calling Guide
- π i18n Documentation
- π― Content-Based Routing
- π Custom Routing Functions
- π§ Transformer Pipeline
- π Cache Warmer
- π Tracing Implementation
- β±οΈ Dynamic TTL Implementation
-
Long Context Routing - Automatically route requests with >60K tokens to Gemini
-
-
60K token Gemini
-
-
Task-Based Routing - Route code review, analysis, or creative tasks to specific models
-
Image Processing - Route requests with images to vision-capable models
-
Tool Usage Optimization - Route tool-calling requests to models with best function-calling support
-
Cost Optimization - Route requests to channels with different pricing tiers
-
High Availability - Automatic failover between multiple API providers
-
- API
-
Rate Limit Management - Distribute load across accounts to avoid limits
-
Multi-Region Routing - Route to nearest or fastest endpoint
Routex/
βββ src/
β βββ server.ts # Main server entry
β βββ core/ # Core business logic
β β βββ proxy.ts # Request proxy engine with tracing
β β βββ loadbalancer.ts # Load balancing (4 strategies)
β β βββ routing/ # SmartRouter system
β β β βββ smart-router.ts # Intelligent routing engine
β β βββ metrics.ts # Metrics collector (Counter/Gauge/Histogram/Summary)
β β βββ prometheus.ts # Prometheus exporter
β β βββ tracing.ts # Distributed request tracing β NEW
β β βββ tee-stream.ts # Request/response replication
β β βββ errors.ts # Error handling
β βββ transformers/ # Format transformers
β β βββ base.ts # Base transformer interface
β β βββ anthropic.ts # Anthropic Messages format
β β βββ openai.ts # OpenAI Chat Completions format
β β βββ maxtoken.ts # Max tokens limiter
β β βββ sampling.ts # Sampling parameter converter
β β βββ index.ts # Transformer manager
β βββ providers/ # AI provider abstractions β NEW
β β βββ anthropic.ts # Anthropic (Claude)
β β βββ openai.ts # OpenAI (GPT)
β β βββ azure.ts # Azure OpenAI
β β βββ google.ts # Google (Gemini)
β β βββ zhipu.ts # Zhipu AI
β β βββ custom.ts # Custom providers
β βββ i18n/ # Internationalization β NEW
β β βββ index.ts # i18n system
β β βββ locales/ # Translation files
β β βββ en.ts # English
β β βββ zh-CN.ts # Chinese (Simplified)
β βββ db/ # Database layer
β β βββ database.ts # SQLite operations with WAL mode
β β βββ migrations.ts # Schema migrations
β βββ api/ # HTTP API routes
β β βββ routes.ts # Main route definitions
β β βββ routing.ts # Routing rules API
β β βββ transformers.ts # Transformers API
β βββ utils/ # Utilities
β β βββ logger.ts # Structured logging (pino)
β β βββ lru-cache.ts # LRU cache with TTL
β βββ services/ # Business services
β β βββ channel-tester.ts # Channel connectivity testing
β βββ config/ # Configuration
β βββ config.ts # Config management
β βββ wizard.ts # Interactive setup wizard
βββ dashboard/ # React 19 + Tailwind CSS 4 dashboard
β βββ src/
βββ tests/ # Test suite (89 tests, 100% pass) β NEW
β βββ loadbalancer.test.ts
β βββ metrics.test.ts
β βββ i18n.test.ts
β βββ prometheus.test.ts
βββ public/ # Static assets
βββ deploy/ # Deployment configs
β βββ claw.yaml
β βββ railway.yaml
β βββ fly.toml
βββ docs/ # Documentation
βββ .github/ # CI/CD workflows β NEW
βββ workflows/
βββ ci.yml # Continuous integration
βββ release.yml # Automated releases
βββ codeql.yml # Security scanning
Routex is built from the ground up for simplicity and performance: Routex ****
-
β‘ 66% less code than traditional monorepo architecture
-
monorepo 66%
-
π <1s startup time vs 5-10s for complex systems
-
πΎ <100MB memory footprint in production
-
<100MB
-
π Free tier compatible - runs on claw.run, Fly.io, Railway
-
- claw.runFly.ioRailway
Contributions are welcome! Please read our Contributing Guide first. (./docs/contributing.md)
MIT License - see LICENSE for details.
Routex is inspired by several excellent open-source projects:
- ccflare by @snipeship - Project architecture inspiration
- claude-code-router by @musistudio - Smart routing patterns
- llmio by @atopos31 - Intelligent load balancing
- cc-switch by @farion1231 - Configuration management UI
All implementations are original work by dctx-team with independent copyright.
Route smarter, scale faster with Routex π―
** Routex ** π―