A unified interface for various LLM providers
Project description
indoxRouter
A unified interface for various LLM providers
Overview
indoxRouter is a powerful Python library that provides a unified interface to interact with various Large Language Model (LLM) providers. With a single API key, you can access models from OpenAI, Anthropic, Mistral, Google, and more, without having to manage multiple provider-specific API keys and implementations.
Key Features
- Single API for Multiple Providers: Access models from OpenAI, Anthropic, Mistral, Google, and more with a single API key
- Standardized Response Format: Consistent response format across all providers
- Streaming Support: Stream responses for real-time applications
- Cost Tracking: Track token usage and costs across providers
- Rate Limiting: Built-in rate limiting to prevent exceeding provider quotas
- Error Handling: Comprehensive error handling with detailed error messages
- Authentication: Secure authentication with JWT tokens
- Type Hints: Full type hints for better IDE support
Installation
pip install indoxRouter
For development:
pip install indoxRouter[dev]
Quick Start
from indoxRouter import Client
from indoxRouter.models import ChatMessage
# Initialize the client with your API key
client = Client(api_key="your-api-key")
# Chat completion with OpenAI
response = client.chat(
messages=[
{"role": "user", "content": "What are three fun activities to do in New York?"}
],
model="openai/gpt-4o-mini",
temperature=0.7,
max_tokens=500,
)
print(response.data)
Available Providers
indoxRouter supports the following providers:
- OpenAI
- Anthropic (Claude)
- Mistral
- Cohere
Core Features
Chat Completion
response = client.chat(
messages=[
{"role": "user", "content": "What are three fun activities to do in New York?"}
],
model="openai/gpt-4o-mini",
temperature=0.7,
max_tokens=500,
)
Text Completion
response = client.completion(
prompt="Write a short story about a robot learning to paint.",
model="anthropic/claude-3-haiku",
temperature=0.7,
max_tokens=500,
)
Embeddings
response = client.embeddings(
text="This is a sample text to embed.",
model="openai/text-embedding-3-small",
)
Image Generation
response = client.image(
prompt="A futuristic city with flying cars and neon lights",
model="openai/dall-e-3",
size="1024x1024",
)
Streaming
generator = client.chat(
messages=[
{"role": "user", "content": "Write a short story about a robot learning to paint."}
],
model="openai/gpt-4o-mini",
temperature=0.7,
max_tokens=500,
stream=True,
return_generator=True,
)
for chunk in generator:
if isinstance(chunk, dict) and chunk.get("is_usage_info"):
# This is the final usage info
usage_info = chunk
else:
# This is a content chunk
print(chunk, end="", flush=True)
Provider and Model Information
# List all available providers
providers = client.providers()
# List all available models
models = client.models()
# List models for a specific provider
openai_models = client.models(provider="openai")
# Get information about a specific model
model_info = client.model_info(provider="openai", model="gpt-4o-mini")
Configuration
indoxRouter can be configured using environment variables or a configuration file:
# Set API key via environment variable
import os
os.environ["INDOX_ROUTER_API_KEY"] = "your-api-key"
# Or provide it directly to the client
client = Client(api_key="your-api-key")
Error Handling
indoxRouter provides comprehensive error handling:
from indoxRouter import Client
from indoxRouter.exceptions import AuthenticationError, RateLimitError, ProviderError
try:
client = Client(api_key="invalid-api-key")
except AuthenticationError as e:
print(f"Authentication error: {e}")
try:
response = client.chat(
messages=[{"role": "user", "content": "Hello"}],
model="nonexistent-model",
)
except ProviderError as e:
print(f"Provider error: {e}")
Documentation
For detailed documentation, visit https://docs.indoxrouter.com.
Examples
Check out the examples directory for more examples.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file indoxrouter-0.1.1.tar.gz.
File metadata
- Download URL: indoxrouter-0.1.1.tar.gz
- Upload date:
- Size: 36.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38e0d8832b651f99bcf81f490e4bda8bc8d97b5612794a1750feb6bf38ff2b84
|
|
| MD5 |
71a8dbc234ec5dcc2e70f2b2f15fd6ac
|
|
| BLAKE2b-256 |
d656db69bac30fc56bfd1bd5639f39bcf513032667c0e2acf1b7a846c6d607b4
|
File details
Details for the file indoxRouter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: indoxRouter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 46.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ee00d9c94369f52b91e377453eaf74ff2306d4cd20dc64ddcce6228f5bc8bcd
|
|
| MD5 |
52124164048775a551cf529132935335
|
|
| BLAKE2b-256 |
c750a9118efd0831a4b8ddb8ed2253985e9fa568cf1e902957ab4436bf019e5e
|