A Python client for the OmniRouter API
Project description
OmniLabs Python Client
A powerful Python client for the OmniRouter API that provides unified access to various LLM models through a single interface. This client supports chat completions, image generation, and smart model selection capabilities.
Installation
pip install omnilabs
Quick Start
from omnilabs import OmniClient, ChatMessage
# Initialize the client
client = OmniClient() # API key can be set via OMNI_API_KEY environment variable
# Or provide the API key directly
client = OmniClient(api_key="your-api-key")
# Simple chat completion
messages = [
ChatMessage(role="user", content="What is the capital of France?")
]
response = client.chat(messages, model="gpt-4")
# Generate an image
image_response = client.generate_image(
prompt="A serene landscape with mountains at sunset",
model="dall-e-3",
size="1024x1024"
)
# Smart model selection
smart_response = client.smart_select(
messages=messages,
k=5, # Get top 5 recommended models
rel_cost=0.5,
rel_accuracy=0.5
)
Features
1. Chat Completions
- Support for various chat models (e.g., GPT-4, Claude, etc.)
- Customizable parameters like temperature and max tokens
- Streaming support for real-time responses
2. Image Generation
- Support for models like DALL-E 3
- Multiple size options: 256x256, 512x512, 1024x1024
- Quality settings: standard and HD
3. Smart Model Selection
- Intelligent model recommendations based on your requirements
- Balance between cost, latency, and accuracy
- Customizable weights for different factors
API Reference
ChatMessage Class
ChatMessage(role: str, content: str)
Represents a single message in a chat conversation.
OmniClient Class
OmniClient(api_key: Optional[str] = None, base_url: str = "https://omni-router.vercel.app/")
Methods:
-
chat(messages, model, temperature=0.7, max_tokens=None, stream=False)- Send chat messages and get completions
- Supports streaming for real-time responses
-
generate_image(prompt, model="dall-e-3", size="1024x1024", quality="standard", n=1)- Generate images from text prompts
- Multiple size and quality options
-
smart_select(messages, k=5, model_names=None, rel_cost=0.5, rel_latency=0.0, rel_accuracy=0.5)- Get model recommendations based on your requirements
- Customize importance of cost, latency, and accuracy
-
get_available_models(model_type=None)- List available models
- Optional filtering by model type ('chat' or 'image')
Environment Variables
OMNI_API_KEY: Your OmniLabs API key
Error Handling
The client includes proper error handling for common scenarios:
- Invalid API keys
- Network issues
- Rate limiting
- Invalid parameters
Contributing
We welcome contributions! Please check our GitHub repository for guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Documentation: https://omnilabs-ai.github.io
- Issues: GitHub Issues
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 omnilabs-0.0.1.tar.gz.
File metadata
- Download URL: omnilabs-0.0.1.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4555b06ef27da74bb7faed9ee8368a084839447bcad4c240ad10cbe20a5c47b3
|
|
| MD5 |
1939edef34436aeb627301fda6558b5c
|
|
| BLAKE2b-256 |
737c0769f3263dcc912e6e9289a97eea52cf0062020be29c84202cfdae24ed6c
|
File details
Details for the file omnilabs-0.0.1-py3-none-any.whl.
File metadata
- Download URL: omnilabs-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
919e3ef5dd7bc7438507f8786f4dd388d716bb64a4b9650db24c99cd47f5715e
|
|
| MD5 |
a4f63226e68f2004609e1a4fd5a833f5
|
|
| BLAKE2b-256 |
787415d2ae92bc86e43224d6f43ab853ee3058402c323eb4f72baf8e7fe4213d
|