Skip to main content

A robust wrapper for LiteLLM with retry logic and rate limiting

Project description

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

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

litellm_retry_wrapper-0.1.0.tar.gz (173.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

litellm_retry_wrapper-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file litellm_retry_wrapper-0.1.0.tar.gz.

File metadata

  • Download URL: litellm_retry_wrapper-0.1.0.tar.gz
  • Upload date:
  • Size: 173.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for litellm_retry_wrapper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 711ffe70f4c1e2eb4697b3b2d07757596bad79427b2724a7007524d4b10624f3
MD5 430152dbd4fec627a350404a540e3231
BLAKE2b-256 825e0b5282b99790af7ffee916c0c4ff6958c1113a85eb1b0d623bbb942f898c

See more details on using hashes here.

File details

Details for the file litellm_retry_wrapper-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for litellm_retry_wrapper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a856ca9bcd0ce6eeaa49647eb59a243651feacf546ab9fceb36f2b3a055bd4d
MD5 4ddf850f4299059a04bf3b4e806535b2
BLAKE2b-256 c3e6fe1bbcfafe4b096c4d1c2a2d136a99b435c915380d6d5b10a0579cca1ec6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page