Skip to main content

Intelligent routing and orchestration for multi-model AI coding agents

Project description

codex-router

License: MIT

Intelligent routing and orchestration for multi-model AI coding agents

codex-router is a lightweight CLI tool that automatically routes coding tasks to the best available AI model (Claude, GPT, Gemini, or local) based on task complexity, cost, and availability. Manage parallel agent sessions, track token usage and costs across providers, and get unified output streaming. Makes it trivial to leverage multiple AI models without manual context switching.

Features

  • Smart routing: Analyzes task complexity and routes to optimal model (fast models for simple tasks, frontier models for complex ones)
  • Parallel orchestration: Run multiple AI agents on different subtasks simultaneously with unified output
  • Cost tracking: Real-time token usage and cost monitoring across all providers (Claude, OpenAI, Gemini)
  • Auto-fallback: Automatically switches to alternative model if primary hits rate limits or errors
  • Unified config: Single configuration file for all API keys and preferences
  • Session management: Save and resume multi-agent sessions with full context
  • ASCII-only output: Cross-platform terminal compatibility (Windows, macOS, Linux)

Installation

Install via pip:

pip install codex-router

Quick Start

Configure your API keys:

codex-router config --set anthropic_api_key YOUR_CLAUDE_KEY
codex-router config --set openai_api_key YOUR_OPENAI_KEY
codex-router config --set google_api_key YOUR_GEMINI_KEY

Set default preferences:

codex-router config --set-default-model claude

Usage Examples

Run a single coding task with intelligent model selection:

codex-router task "refactor auth module"

Output:

[Router] Analyzing task complexity...
[Router] Task complexity: HIGH -> Selected model: claude-opus-4
[Agent-1] Reading auth module...
[Agent-1] Identified 3 refactoring opportunities
[Agent-1] Applying changes...
[Agent-1] DONE - 2,450 tokens used ($0.073)

Run parallel agents on multiple subtasks:

codex-router task "add unit tests" --parallel 2

Output:

[Router] Splitting task into 2 parallel agents
[Agent-1] Testing user authentication flow...
[Agent-2] Testing database connections...
[Agent-1] Created 5 test cases
[Agent-2] Created 3 test cases
[Router] DONE - Total: 3,120 tokens ($0.094)

Constrain budget for cost control:

codex-router task "add unit tests" --model claude --budget 0.50

Check usage statistics:

codex-router status --show-costs

Output:

Token Usage Summary (Last 7 Days)
---------------------------------
Provider    | Tokens  | Cost
---------------------------------
Claude      | 45,230  | $1.35
OpenAI      | 12,500  | $0.25
Gemini      | 8,900   | $0.00
---------------------------------
Total                 | $1.60

Configuration

Configuration is stored in ~/.codex-router/config.yaml. You can edit it manually or use the CLI:

# Set API keys
codex-router config --set anthropic_api_key YOUR_KEY
codex-router config --set openai_api_key YOUR_KEY
codex-router config --set google_api_key YOUR_KEY

# Set default model
codex-router config --set-default-model gpt-4

# Set budget limits
codex-router config --set daily_budget 5.00

How It Works

  1. Task Analysis: The router analyzes your task description for complexity, required context, and estimated token usage
  2. Model Selection: Based on complexity and your preferences, selects the optimal model (e.g., GPT-3.5 for simple tasks, Claude Opus for complex refactoring)
  3. Execution: Sends the task to the selected provider's API with proper context and streaming
  4. Cost Tracking: Records token usage and costs in a local database for monitoring
  5. Auto-Fallback: If the primary model fails (rate limit, timeout), automatically retries with an alternative model

Development

Clone the repository:

git clone https://github.com/Intellirim/codex-router.git
cd codex-router

Install in development mode:

pip install -e .

Run tests:

pytest tests/

License

MIT License - Copyright (c) 2026 Intellirim

Contributing

Contributions welcome! Please open an issue or submit a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codex_router-0.2.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codex_router-0.2.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file codex_router-0.2.0.tar.gz.

File metadata

  • Download URL: codex_router-0.2.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.2

File hashes

Hashes for codex_router-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4ca43957408c396aa7b1c54426240c466564994bcb0405c1ec914dd52f4f5b84
MD5 541c22854bc3042296d7ceb1187b4003
BLAKE2b-256 f0cfdb52b7f15163f875c715a1473b093d986582cbdf91fb7faf2ae3d4748ae3

See more details on using hashes here.

File details

Details for the file codex_router-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: codex_router-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.2

File hashes

Hashes for codex_router-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02a1932bda298b38d7e96f73f078620063213c72376c3952c02789e58eb5ea82
MD5 5ffc040c8ca2921482516da2ed2d6d9a
BLAKE2b-256 68e0d17ef31db029a883c5a3603d891c3e4e04a996876a752786bddadb27e958

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page