Skip to main content

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

  1. Deploy the UniLLM API gateway (see Deployment Guide)
  2. Register and get your API key from the dashboard
  3. 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)

  1. 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
    
  2. Deploy to Cloud:

    • Railway: Easy deployment with automatic HTTPS
    • Render: Free tier available
    • Heroku: Simple deployment
    • DigitalOcean: More control
  3. Update Client Base URL:

    client = UniLLM(
        api_key="your-api-key",
        base_url="https://your-deployed-api.com"
    )
    

Option 2: Local Development

  1. Start the API Gateway:

    cd api_gateway
    python main_phase2.py
    
  2. 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 examples
  • advanced_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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

📄 License

MIT License - see LICENSE file for details.

🆘 Support

🗺️ 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

unifyllm_sdk-0.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

unifyllm_sdk-0.1.0-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

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

Hashes for unifyllm_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 79277ef1a93e63237c65d6946b7d2edada3fd344ad1c602b9f4a3c120ea2d793
MD5 d7699bd133a163c2f8fef2b3250e5445
BLAKE2b-256 6088d2c2889fd03dba589d0c883c1dade4f0af5893941803dc52cddcd8ac98a3

See more details on using hashes here.

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

Hashes for unifyllm_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d70abce5181c8293df0278d7ecf1a99fcf19d2bebbbcde32eb29bc9fbe68d1c
MD5 c5965711d595bd1e912e8df177b96ca9
BLAKE2b-256 d2078793bc277fa66771cd506ee231ee10e5bbb97f77b5ad9333d3fe548bd7e5

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