A unified Python library for accessing multiple LLM providers with a single API key
Project description
UniLLM - Unified API Gateway for Multiple LLM Providers
A unified API gateway that provides a single API key interface for multiple LLM providers (OpenAI, Anthropic, Google, etc.) with built-in usage tracking, billing, and a modern web dashboard.
🎯 What is UniLLM?
UniLLM solves the complexity of managing multiple LLM API keys by providing:
- Single API Key: Use one key to access all supported providers
- Automatic Provider Selection: Smart routing based on model names
- Usage Tracking: Built-in analytics and cost monitoring
- Modern Dashboard: React-based web interface for management
- Credit System: Pre-paid credits with automatic deduction
🚀 Quick Start
1. Install the Client Library
pip install unillm
2. Get Your API Key
- Deploy the UniLLM API gateway (see Deployment Guide)
- Register and get your API key from the dashboard
- Set your API key:
export UNILLM_API_KEY="your-api-key-here"
3. Basic Usage
Simple Chat
from unillm import chat
response = chat(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.content)
Using the Client Class
from unillm import UniLLM
client = UniLLM(api_key="your-api-key")
response = client.chat(
model="gpt-4",
messages=[{"role": "user", "content": "What's 2+2?"}],
temperature=0.7
)
print(response.content)
Conversation Example
conversation = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "My name is Alice."},
{"role": "assistant", "content": "Hello Alice! Nice to meet you."},
{"role": "user", "content": "What's my name?"}
]
response = client.chat(model="gpt-4", messages=conversation)
print(response.content) # "Your name is Alice!"
📋 Supported Models
UniLLM automatically routes to the correct provider based on the model name:
- OpenAI:
gpt-4,gpt-4-turbo,gpt-3.5-turbo, etc. - Anthropic:
claude-3-sonnet,claude-3-haiku,claude-2.1, etc. - Google:
gemini-pro,gemini-pro-vision, etc. - Mistral:
mistral-large,mistral-medium, etc. - Cohere:
command,command-light, etc.
🔧 Configuration
Environment Variables
export UNILLM_API_KEY="your-api-key"
export UNILLM_BASE_URL="https://your-api-gateway.com" # Optional, defaults to localhost:8000
Client Configuration
client = UniLLM(
api_key="your-api-key",
base_url="https://your-api-gateway.com"
)
📊 Usage Tracking
The client automatically tracks usage through your API gateway:
- Token usage (prompt, completion, total)
- Cost tracking per model
- Request history
- Analytics dashboard
🚀 Deployment
Option 1: Deploy to Production (Recommended)
-
Deploy the API Gateway:
# Clone and setup git clone https://github.com/yourusername/unillm cd unillm/api_gateway # Install dependencies pip install -r requirements_phase2.txt # Set environment variables export OPENAI_API_KEY="your-openai-key" export ANTHROPIC_API_KEY="your-anthropic-key" # ... other provider keys # Run the server python main_phase2.py
-
Deploy to Cloud:
- Railway: Easy deployment with automatic HTTPS
- Render: Free tier available
- Heroku: Simple deployment
- DigitalOcean: More control
-
Update Client Base URL:
client = UniLLM( api_key="your-api-key", base_url="https://your-deployed-api.com" )
Option 2: Local Development
-
Start the API Gateway:
cd api_gateway python main_phase2.py
-
Use the Client:
client = UniLLM(api_key="your-api-key") # Uses localhost:8000 by default
🎨 Dashboard
Access the modern React dashboard for:
- User Management: Register, login, manage API keys
- Usage Analytics: Real-time usage statistics
- Billing: Credit purchase and management
- Chat Interface: Test models directly
- API Keys: Manage your keys
Launch Dashboard
cd api_gateway
python launch_dashboard.py
Then visit: http://localhost:8501
📚 Examples
See the examples/ directory for more usage examples:
simple_client_example.py- Basic usage examplesadvanced_usage.py- Advanced features and patterns
🧪 Testing
Test your setup:
# Test the client library
python test_client_library.py
# Test the API gateway
cd api_gateway
python test_phase2.py
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
📄 License
MIT License - see LICENSE file for details.
🆘 Support
- Issues: GitHub Issues
- Documentation: GitHub Wiki
- Discussions: GitHub Discussions
🗺️ Roadmap
- Streaming support
- More provider integrations
- Advanced analytics
- Team management
- API rate limiting
- Webhook support
UniLLM - Simplify your LLM integration with a unified API gateway.
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
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 unifyllm_sdk-0.1.0.tar.gz.
File metadata
- Download URL: unifyllm_sdk-0.1.0.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79277ef1a93e63237c65d6946b7d2edada3fd344ad1c602b9f4a3c120ea2d793
|
|
| MD5 |
d7699bd133a163c2f8fef2b3250e5445
|
|
| BLAKE2b-256 |
6088d2c2889fd03dba589d0c883c1dade4f0af5893941803dc52cddcd8ac98a3
|
File details
Details for the file unifyllm_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: unifyllm_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d70abce5181c8293df0278d7ecf1a99fcf19d2bebbbcde32eb29bc9fbe68d1c
|
|
| MD5 |
c5965711d595bd1e912e8df177b96ca9
|
|
| BLAKE2b-256 |
d2078793bc277fa66771cd506ee231ee10e5bbb97f77b5ad9333d3fe548bd7e5
|