Skip to content
dctx-teamPublic

About

Route smarter, scale faster

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

50 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Routex 🎯

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

License: MIT Bun Version

✨ Features

🎯 v1.1.0 New Features

  • 🧠 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

πŸ”§ Core Features

  • πŸ”€ 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

πŸš€ Quick Start

Installation

# 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 start

First Run Setup

On first run, Routex will guide you through a 3-step setup wizard: Routex 3

  1. Add your first AI channel (Anthropic Claude, OpenAI, etc.) AI Anthropic ClaudeOpenAI

  2. Configure load balancing strategy

  3. Set up dashboard access credentials

🎯 SmartRouter Usage / SmartRouter

Creating Routing Rules

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
  }'

πŸ”„ Transformers Usage / Transformers

Configuring Channel Transformers / Transformers

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"]
    }
  }'

Testing Transformers / Transformers

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
    }
  }'

πŸ“– Documentation

Core Documentation

Feature Guides

Dashboard & CLI

Testing & Security

🎯 Use Cases

SmartRouter Scenarios / SmartRouter

  • 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

General Scenarios

  • 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

πŸ—οΈ Architecture

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

🌟 Why Routex? / Routex

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

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide first. (./docs/contributing.md)

πŸ“„ License

MIT License - see LICENSE for details.

πŸ™ Acknowledgments

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.

Built with Bun and Hono.


Route smarter, scale faster with Routex 🎯

** Routex ** 🎯

About

Route smarter, scale faster

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages