Unified Python interface for multiple AI providers with support for text, images, and documents.
Project description
Multi AI Handler
A unified Python library for interacting with multiple AI providers through a consistent interface. Supports text and file inputs across OpenAI, Anthropic Claude, Google Gemini, OpenRouter, Cerebras and Ollama (local LLMs).
Features
- Unified interface for multiple AI providers
- Streaming support for real-time token output
- Async support for concurrent workloads
- Support for images and documents (PDF)
- Local LLM support with Ollama
- Advanced document processing with Docling (OCR, table extraction)
- Model information retrieval
Installation
pip install multi-ai-handler
Optional dependencies:
pip install multi-ai-handler[ollama] # Local LLM support
pip install multi-ai-handler[docling] # Document processing (OCR, tables)
pip install multi-ai-handler[all] # All optional dependencies
Setup
Create a .env file with your API keys:
ANTHROPIC_API_KEY=your_anthropic_api_key_here
CEREBRAS_API_KEY=your_cerebras_api_key_here
GEMINI_API_KEY=your_gemini_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
OPENROUTER_API_KEY=your_openrouter_api_key_here
Usage
Basic Request
from multi_ai_handler import request_ai
response = request_ai(
provider="google", # or "anthropic", "openai", "openrouter", "cerebras", "ollama"
model="gemini-2.5-flash",
system_prompt="You are a helpful assistant.",
user_text="What is the capital of France?"
)
JSON Output
data = request_ai(
provider="google",
model="gemini-2.5-flash",
system_prompt="Return valid JSON only.",
user_text="Convert to JSON: Name: Alice, Age: 25",
json_output=True
)
# Returns: {'name': 'Alice', 'age': 25}
File Processing
response = request_ai(
provider="anthropic",
model="claude-sonnet-4-5-20250929",
system_prompt="Summarize this document.",
file="document.pdf"
)
Streaming
from multi_ai_handler import stream_ai
for chunk in stream_ai(provider="google", model="gemini-2.0-flash", user_text="Write a poem"):
print(chunk, end="", flush=True)
Async Support
import asyncio
from multi_ai_handler import arequest_ai, astream_ai
async def main():
# Concurrent requests
responses = await asyncio.gather(
arequest_ai(provider="google", model="gemini-2.0-flash", user_text="Hello"),
arequest_ai(provider="anthropic", model="claude-sonnet-4-20250514", user_text="Hello"),
)
# Async streaming
async for chunk in astream_ai(provider="google", model="gemini-2.0-flash", user_text="Hi"):
print(chunk, end="", flush=True)
asyncio.run(main())
Model Information
from multi_ai_handler import list_models, get_model_info
all_models = list_models() # {'google': [...], 'anthropic': [...], ...}
info = get_model_info(provider="google", model="models/gemini-2.0-flash")
API Reference
Functions
| Function | Description |
|---|---|
request_ai(provider, model, ...) |
Generate a response |
stream_ai(provider, model, ...) |
Stream response tokens |
arequest_ai(provider, model, ...) |
Async generation |
astream_ai(provider, model, ...) |
Async streaming |
list_models() |
List all available models |
get_model_info(provider, model) |
Get model metadata |
Parameters
| Parameter | Type | Description |
|---|---|---|
provider |
str | "google", "anthropic", "openai", "openrouter", "cerebras", "ollama" |
model |
str | Model name (e.g., "gemini-2.5-flash", "claude-sonnet-4-5-20250929") |
system_prompt |
str | System instruction |
user_text |
str | User input text |
file |
str/Path | File path for images or documents |
temperature |
float | Randomness (0.0-1.0), default: 0.2 |
json_output |
bool | Parse response as JSON, default: False |
local |
bool | Use local text extraction (Docling), default: False |
Classes
AIProviderManager- Manage providers, register custom providersAIProvider- Abstract base class for implementing custom providers- Provider classes:
AnthropicProvider,GoogleProvider,OpenAIProvider,OpenrouterProvider,OllamaProvider,CerebrasProvider
License
MIT
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
Support
For issues and questions, please open an issue on the GitHub repository.
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 multi_ai_handler-2.1.0.tar.gz.
File metadata
- Download URL: multi_ai_handler-2.1.0.tar.gz
- Upload date:
- Size: 167.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d95b4e9d28c15fd5acb9f311a82f203d5400f72e0f9b106f506d9fbc4eafae5
|
|
| MD5 |
2e17350811c8d4d648300bed666a3ab2
|
|
| BLAKE2b-256 |
80b616b5da1a58099d3f57a9d7af0c823f678fe418f63ad686c8a3977e3cd462
|
Provenance
The following attestation bundles were made for multi_ai_handler-2.1.0.tar.gz:
Publisher:
publish.yml on vsharha/multi-ai-handler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
multi_ai_handler-2.1.0.tar.gz -
Subject digest:
6d95b4e9d28c15fd5acb9f311a82f203d5400f72e0f9b106f506d9fbc4eafae5 - Sigstore transparency entry: 718821278
- Sigstore integration time:
-
Permalink:
vsharha/multi-ai-handler@118c7dcc75c1f028a9caadc4a64cf15c70b3de21 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/vsharha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@118c7dcc75c1f028a9caadc4a64cf15c70b3de21 -
Trigger Event:
release
-
Statement type:
File details
Details for the file multi_ai_handler-2.1.0-py3-none-any.whl.
File metadata
- Download URL: multi_ai_handler-2.1.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7a32d9226beb5b52fe626508da8b937a79c2532f0e733acecd60b4c94ec2159
|
|
| MD5 |
fae58c80fcb62a888ed22993f2faa74e
|
|
| BLAKE2b-256 |
a9887e9a4c605d3c21c91a8b0fbf3e5b2004b7c6b51dacb84e08a64668226554
|
Provenance
The following attestation bundles were made for multi_ai_handler-2.1.0-py3-none-any.whl:
Publisher:
publish.yml on vsharha/multi-ai-handler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
multi_ai_handler-2.1.0-py3-none-any.whl -
Subject digest:
c7a32d9226beb5b52fe626508da8b937a79c2532f0e733acecd60b4c94ec2159 - Sigstore transparency entry: 718821279
- Sigstore integration time:
-
Permalink:
vsharha/multi-ai-handler@118c7dcc75c1f028a9caadc4a64cf15c70b3de21 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/vsharha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@118c7dcc75c1f028a9caadc4a64cf15c70b3de21 -
Trigger Event:
release
-
Statement type: