Lightweight Python wrapper for LiteLLM with simplified interface for 100+ AI providers. Supports text, images, and documents with conversation management.
Project description
litellm_utils
A lightweight Python wrapper around LiteLLM that provides a simplified interface for interacting with multiple AI providers. Supports text and file inputs across 100+ LLMs including OpenAI, Anthropic Claude, Google Gemini, and more.
Features
- Simple unified interface built on LiteLLM
- Conversation history for multi-turn interactions
- Streaming support for real-time token output
- Support for images and documents (PDF)
- Advanced document processing with Docling (OCR, table extraction)
- Automatic PDF handling based on model capabilities
- Access to 100+ LLMs through LiteLLM
Installation
pip install litellm_utils
Optional dependencies:
pip install litellm_utils[docling] # Document processing (OCR, tables)
pip install litellm_utils[all] # All optional dependencies
Setup
Configure your API keys as environment variables. LiteLLM supports many providers:
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
GEMINI_API_KEY=your_gemini_api_key_here
# ... and many more providers supported by LiteLLM
See LiteLLM documentation for all supported providers.
Usage
Basic Request
from litellm_utils 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="openai",
model="gpt-4o-mini",
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 litellm_utils import stream_ai
for chunk in stream_ai(
provider="openai",
model="gpt-4o-mini",
user_text="Write a poem about Python"
):
print(chunk, end="", flush=True)
Conversation History
Use the Conversation class for multi-turn interactions:
from litellm_utils import Conversation
conv = Conversation(
provider="anthropic",
model="claude-sonnet-4-20250514",
system_prompt="You are a helpful assistant."
)
response = conv.send("My name is Alice.")
print(response)
response = conv.send("What's my name?") # Remembers context
print(response)
conv.clear_history() # Reset conversation
With streaming:
conv = Conversation(provider="openai", model="gpt-4o-mini")
for chunk in conv.stream("Tell me a story"):
print(chunk, end="", flush=True)
With file processing:
conv = Conversation(provider="google", model="gemini-2.0-flash")
response = conv.send("Summarize this document", file="report.pdf")
print(response)
response = conv.send("What are the key findings?") # Follows up on context
print(response)
Model Information
from litellm_utils import list_models
# List models for a specific provider
openai_models = list_models("openai")
anthropic_models = list_models("anthropic")
API Reference
Functions
request_ai(provider, model, **kwargs)
Generate a response from an AI model.
Parameters:
provider(str): Provider name (e.g.,"openai","anthropic","google")model(str): Model name (e.g.,"gpt-4o-mini","claude-sonnet-4-20250514")system_prompt(str, optional): System instructionuser_text(str, optional): User input textmessages(list[dict], optional): Conversation history in OpenAI formatfile(str/Path, optional): Path to image or document filetemperature(float, optional): Sampling temperature (0.0-1.0), default: 0.2json_output(bool, optional): Parse response as JSON, default: Falsepreprocess_file_content(bool, optional): Use Docling for document processing, default: False (auto-detected)
Returns: str or dict (if json_output=True)
stream_ai(provider, model, **kwargs)
Stream response tokens from an AI model.
Parameters: Same as request_ai() except json_output
Returns: Iterator[str]
list_models(provider)
List available models for a provider.
Parameters:
provider(str): Provider name
Returns: list[dict]
Classes
Conversation
Multi-turn conversation with automatic history management.
Methods:
__init__(provider, model, system_prompt=None, temperature=0.2)- Initialize conversationsend(user_text, file=None, json_output=False, preprocess_file_content=False)- Send a messagestream(user_text, file=None, preprocess_file_content=False)- Stream a responseget_history()- Get conversation historyclear_history()- Clear conversation historyset_system_prompt(system_prompt)- Update system prompt
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
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 litellm_utils-1.0.0.tar.gz.
File metadata
- Download URL: litellm_utils-1.0.0.tar.gz
- Upload date:
- Size: 216.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c3e0d92545ef8a5e1112b920eadd45588a41998676ed2771146d45c1538db8e
|
|
| MD5 |
a0d2348b3c29f6905694b84271b0b249
|
|
| BLAKE2b-256 |
8b71d6bfb2495fc7515623bd4d9f636d56c918119fb7d136750950cb574a1221
|
Provenance
The following attestation bundles were made for litellm_utils-1.0.0.tar.gz:
Publisher:
publish.yml on vsharha/litellm_utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litellm_utils-1.0.0.tar.gz -
Subject digest:
7c3e0d92545ef8a5e1112b920eadd45588a41998676ed2771146d45c1538db8e - Sigstore transparency entry: 725007582
- Sigstore integration time:
-
Permalink:
vsharha/litellm_utils@ea289cafdd4517c6b20bf37dabd3e8865c22cc68 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/vsharha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea289cafdd4517c6b20bf37dabd3e8865c22cc68 -
Trigger Event:
release
-
Statement type:
File details
Details for the file litellm_utils-1.0.0-py3-none-any.whl.
File metadata
- Download URL: litellm_utils-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.8 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 |
018dbc0de1c4cf8fe7b98c923d177e8be5a186812e7044472bd1865cd9019669
|
|
| MD5 |
c6b9e6aa83109054722f1ae180dd433e
|
|
| BLAKE2b-256 |
f743aecd12ca981b3305e5ed0c316cfc93a8f9206578238e30b4cc9f2c73df09
|
Provenance
The following attestation bundles were made for litellm_utils-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on vsharha/litellm_utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litellm_utils-1.0.0-py3-none-any.whl -
Subject digest:
018dbc0de1c4cf8fe7b98c923d177e8be5a186812e7044472bd1865cd9019669 - Sigstore transparency entry: 725007583
- Sigstore integration time:
-
Permalink:
vsharha/litellm_utils@ea289cafdd4517c6b20bf37dabd3e8865c22cc68 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/vsharha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea289cafdd4517c6b20bf37dabd3e8865c22cc68 -
Trigger Event:
release
-
Statement type: