Simple Multi-Provider LLM Gateway
Project description
ModelBridge
Simple Multi-Provider LLM Gateway
ModelBridge is a Python library that provides unified access to multiple AI providers. It simplifies working with OpenAI, Anthropic, Google, and Groq APIs through a single interface.
✨ What it Does
- Multi-Provider Support: Works with OpenAI, Groq, Google, and Anthropic
- Smart Model Selection: Automatically picks models based on your task
- Cost Tracking: Shows you how much each request costs
- Simple API: One function (
ask) for most use cases - Environment Variables: Secure API key management
🚀 Quick Start
Installation
pip install modelbridge
Basic Usage
import asyncio
from modelbridge.simple import ask
# Set your API keys as environment variables:
# export OPENAI_API_KEY='your_openai_key'
# export GROQ_API_KEY='your_groq_key'
async def main():
response = await ask("What is the capital of France?")
print(f"Answer: {response.content}")
print(f"Model: {response.model_id}")
print(f"Provider: {response.provider_name}")
print(f"Cost: ${response.cost:.4f}")
asyncio.run(main())
Advanced Usage
# Specify a particular model
response = await ask("Write Python code", model="gpt-4")
# Optimize for speed, cost, or quality
response = await ask("Simple math", optimize_for="cost")
response = await ask("Complex analysis", optimize_for="quality")
# Set maximum cost limit
response = await ask("Quick question", max_cost=0.001)
# Other useful functions
from modelbridge.simple import code, translate, summarize
# Generate code
response = await code("Create a sorting function", language="python")
# Translate text
response = await translate("Hello world", "Spanish")
# Summarize text
response = await summarize("Long article text here...", length="short")
Configuration
API Keys
Set your API keys as environment variables:
# Add the providers you want to use
export OPENAI_API_KEY='sk-your-openai-key'
export GROQ_API_KEY='gsk_your-groq-key'
export GOOGLE_API_KEY='your-google-key'
export ANTHROPIC_API_KEY='sk-ant-your-anthropic-key'
You need at least one API key for ModelBridge to work.
Supported Providers
- OpenAI: GPT-4, GPT-3.5-turbo, GPT-5-mini
- Groq: Llama 3.3 (very fast)
- Google: Gemini models
- Anthropic: Claude models
How It Works
- You call
ask("your question") - ModelBridge analyzes your prompt
- It picks the best model for the task
- Returns response with cost tracking
- Automatically handles errors and retries
License
MIT License
Simple AI provider integration.
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 modelbridge-0.1.7.tar.gz.
File metadata
- Download URL: modelbridge-0.1.7.tar.gz
- Upload date:
- Size: 229.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8299aadae90a9dfd4f379339f89bfe6132fd4ae7db8c4fffd2cacbd996147c6c
|
|
| MD5 |
1801bdf23a3114a02fca7be70605c3f2
|
|
| BLAKE2b-256 |
efa7612f53082d1a8e9dd8d6fc92e59b5430d185cecc189e72c1cd8e18b78bf8
|
File details
Details for the file modelbridge-0.1.7-py3-none-any.whl.
File metadata
- Download URL: modelbridge-0.1.7-py3-none-any.whl
- Upload date:
- Size: 260.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1795b77961679e267018c47feeb29d3d2f2233ece7f24d0f3d4a81b7d044b867
|
|
| MD5 |
aeee9d0ddfd9443aa508a894099b7ee6
|
|
| BLAKE2b-256 |
9abf6f05953b170fd3a920252ca1d435e0e7b4f727a742644ebf3aca25f0bbb1
|