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.2.tar.gz
(7.6 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.2.tar.gz.
File metadata
- Download URL: llm_limiters-0.1.2.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aba3c52163c5ef92b92e4693bd64d5a1d29c4964ae38ac19947c15000e68eb07
|
|
| MD5 |
449f91fb41fec6e7fb48ea4a37e0c132
|
|
| BLAKE2b-256 |
1d06d42593486431fc77cd7daa48f5eb963a7b4fb6703bf979a482673cdd46ff
|
File details
Details for the file llm_limiters-0.1.2-py3-none-any.whl.
File metadata
- Download URL: llm_limiters-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.8 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 |
11e20d11d0782f9eb9cac66429615d576e63a297d942141b2e498b28dceb4e04
|
|
| MD5 |
6dbdfa9429a60eddb5f6f071c99e97e2
|
|
| BLAKE2b-256 |
fd78bb4cef50e1c5d72e46d3f558e43f2ff75abb621d614959a3a39ae59b4be3
|