Skip to main content

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


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)

Uploaded Source

Built Distribution

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

llm_limiters-0.1.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

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

Hashes for llm_limiters-0.1.1.tar.gz
Algorithm Hash digest
SHA256 39258467f99ccab3b766e4828620f0018fb9a3f2874cf49a5a963bb2f57ba78a
MD5 e89c717ea84e415d768cb0ea4914e1c6
BLAKE2b-256 9b3e072d809b33b9418dfb61d7a9f3d032e1dd7780a2cd9ccbca8b18207fee8a

See more details on using hashes here.

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

Hashes for llm_limiters-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8693b4bb2c100706bbcd32f9f1431169fc0c6247839fb67a8d0d4d372eadd9a6
MD5 0e7726baa12f62c2926905bbfefd4153
BLAKE2b-256 43a82d79101f3e227b075d5a4b1f77e8252972f6c684ab5fc7aed397519f8c4e

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