A thread-safe and async rate limiter for Gemini and OpenAI models.
Project description
LLM Limiters
A lightweight, thread-safe, and async Python library to manage rate limits (RPM, TPM, RPD) for LLMs like Google Gemini and OpenAI.
Installation
pip install llm-limiters
Usage
Standard Rate Limiter (Decorators)
from llm_limiters import RateLimiter
limiter = RateLimiter(tier="free")
@limiter.limit(model_priority=["gemini-2.0-flash", "gpt-4o-mini"])
def call_llm(prompt, model_name=None):
# Your API call here
return response
Live/WebSocket Limiter
import asyncio
from llm_limiters import LiveRateLimiter
async def main():
limiter = LiveRateLimiter(tier="tier1")
allowed, reason = await limiter.check_availability("gemini-2.0-flash-live-001")
if allowed:
await limiter.acquire_session("gemini-2.0-flash-live-001")
# Start websocket...
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
llm_limiters-0.1.1.tar.gz
(6.9 kB
view details)
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 llm_limiters-0.1.1.tar.gz.
File metadata
- Download URL: llm_limiters-0.1.1.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39258467f99ccab3b766e4828620f0018fb9a3f2874cf49a5a963bb2f57ba78a
|
|
| MD5 |
e89c717ea84e415d768cb0ea4914e1c6
|
|
| BLAKE2b-256 |
9b3e072d809b33b9418dfb61d7a9f3d032e1dd7780a2cd9ccbca8b18207fee8a
|
File details
Details for the file llm_limiters-0.1.1-py3-none-any.whl.
File metadata
- Download URL: llm_limiters-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8693b4bb2c100706bbcd32f9f1431169fc0c6247839fb67a8d0d4d372eadd9a6
|
|
| MD5 |
0e7726baa12f62c2926905bbfefd4153
|
|
| BLAKE2b-256 |
43a82d79101f3e227b075d5a4b1f77e8252972f6c684ab5fc7aed397519f8c4e
|