Skip to main content

Intelligent routing of LLM API calls across multiple providers with automatic fallbacks, cost optimization, and monitoring

Project description

AI LLM Router

Intelligent routing of LLM API calls across multiple providers with automatic fallbacks, cost optimization, caching, health monitoring, and retry logic.

Features

  • Multi-Provider Support: OpenAI, Anthropic, and extensible for other providers
  • Intelligent Routing: Priority-based, cost-optimized, and round-robin strategies
  • Automatic Fallbacks: Seamless failover between providers
  • Cost Optimization: Track and optimize API usage costs
  • Caching: Redis-based response caching for improved performance
  • Health Monitoring: Real-time provider health checks
  • Retry Logic: Configurable retry mechanisms with exponential backoff
  • Async Support: Full async/await support for high-performance applications
  • Streaming: Support for streaming responses
  • CLI Interface: Command-line tool for easy integration
  • Metrics: Prometheus-compatible metrics collection

Installation

pip install ai-llm-router

Quick Start

from llm_router import LLMRouter, RouterConfig
from llm_router.providers import OpenAIProvider, AnthropicProvider

# Configure providers
config = RouterConfig(
    providers=[
        OpenAIProvider(api_key="your-openai-key"),
        AnthropicProvider(api_key="your-anthropic-key")
    ],
    strategy="priority"
)

# Create router
router = LLMRouter(config)

# Make a request
response = await router.chat_completion(
    messages=[{"role": "user", "content": "Hello, world!"}],
    model="gpt-4"
)

CLI Usage

After installation, you can use the CLI:

ai-llm-router chat --provider openai --model gpt-4 --message "Hello, world!"

Documentation

For detailed documentation, examples, and API reference, visit our GitHub repository.

Author

Sherin Joseph - LinkedIn

License

MIT License - see LICENSE file for details.

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

ai_llm_router-0.1.0.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

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

ai_llm_router-0.1.0-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

Details for the file ai_llm_router-0.1.0.tar.gz.

File metadata

  • Download URL: ai_llm_router-0.1.0.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for ai_llm_router-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0eecdaca136b66b713b5640a17ce6ddd717430d65f01c8e9eda6f37f10febb81
MD5 50de5a73c46a4c60fa9a40e4a9f2d89c
BLAKE2b-256 4bd0dc31fbd7a92b1b5057ec82a90b05a16442c8e5e1d14923c64837c00ec4db

See more details on using hashes here.

File details

Details for the file ai_llm_router-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ai_llm_router-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for ai_llm_router-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad2c8256c0d6077d7d8c8b780874bd462b18283afce0b827f6c80d0d62b1c476
MD5 3352240c247d41d5d301d00daabad215
BLAKE2b-256 e6afc4817bbd73952cab29647eaa363fb6d56ca265454c41343654645f3f453a

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