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.0.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.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llm_limiters-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 67ad5887029c40ce86da830b26e3f6376c8776d9fd0ba83ac6f8299c7f8092d1
MD5 4f0dfcee29c0ab7f5c05589784572242
BLAKE2b-256 301bf43aea06bcbec0f24ccb66c2ea17db00076499f790ceb9ef1e59bfd208a0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: llm_limiters-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68d61c99db0b42e5b581c630532e08899a832f5cdeef580a4bd7d611a7991d3f
MD5 61b7324abcfef438a7dc58272b614395
BLAKE2b-256 6948c948e5d896a7b5b4dc32765a0571cd0a79eb4bf4d60055a80aaeb4b5d3d3

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