LiteLLM Retry Wrapper
A robust Python wrapper for LiteLLM that provides retry mechanisms, rate limiting, and error handling for LLM API calls.
Features
- 🔄 Automatic retry mechanism with exponential backoff
- ⏱️ Built-in rate limiting
- 🎯 Configurable parameters for retries and rate limits
- 📝 Comprehensive logging
- 🛡️ Error handling and exception management
- 🔧 Easy to customize and extend
Installation
uv pip install litellm-retry-wrapper
Quick Start
from call_litellm_with_retry import LiteLLMCaller
# Initialize the caller
llm_caller = LiteLLMCaller(
model_name="gemini/gemini-2.0-flash",
rpm=2000,
max_retries=3
)
# Prepare your messages
messages = [
{
"role": "user",
"content": "Write a short poem about artificial intelligence."
}
]
# Make the API call
response = llm_caller.complete(
messages=messages,
temperature=0.7,
max_tokens=100
)
print(response.choices[0].message.content)
Configuration
The LiteLLMCaller class accepts the following parameters:
model_name: The name of the LLM model to use (default: "gemini/gemini-2.0-flash")rpm: Rate limit in requests per minute (default: 2000)max_retries: Maximum number of retry attempts (default: 3)min_retry_wait: Minimum wait time between retries in seconds (default: 4)max_retry_wait: Maximum wait time between retries in seconds (default: 10)
Environment Variables
Create a .env file with your API keys:
GEMINI_API_KEY=your_api_key_here
Development
To set up the development environment:
# Clone the repository
git clone https://github.com/sanjeed5/litellm-retry-wrapper.git
cd litellm-retry-wrapper
# Install dependencies
uv venv
source .venv/bin/activate
uv sync
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Metadata
Release files for litellm-retry-wrapper 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| litellm_retry_wrapper-0.1.0.tar.gz | 173.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| litellm_retry_wrapper-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 179.3 kB
Release files / litellm_retry_wrapper-0.1.0.tar.gz
| Download URL | litellm_retry_wrapper-0.1.0.tar.gz |
|---|---|
| Size | 173.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
711ffe70f4c1e2eb4697b3b2d07757596bad79427b2724a7007524d4b10624f3
|
|
BLAKE2b-256 checksum How to use checksums |
825e0b5282b99790af7ffee916c0c4ff6958c1113a85eb1b0d623bbb942f898c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.9
|
Release files / litellm_retry_wrapper-0.1.0-py3-none-any.whl
| Download URL | litellm_retry_wrapper-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a856ca9bcd0ce6eeaa49647eb59a243651feacf546ab9fceb36f2b3a055bd4d
|
|
BLAKE2b-256 checksum How to use checksums |
c3e6fe1bbcfafe4b096c4d1c2a2d136a99b435c915380d6d5b10a0579cca1ec6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.9
|