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.3.tar.gz (7.8 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.3-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llm_limiters-0.1.3.tar.gz
  • Upload date:
  • Size: 7.8 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.3.tar.gz
Algorithm Hash digest
SHA256 933eb05b8893e5a01758dd6b9a4c1565df136365687c5109898986ee340d973d
MD5 1f734008f51af579fd86376b5aa33b0d
BLAKE2b-256 f552061558051ce44a9e1b801fa9d2894626aae09dbabb859f4877747d6973d1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: llm_limiters-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 32ce31e78bc327c60f37de5529a35cc24d330a83859c54178020143d11009386
MD5 d45a19f2ef33cdf08cdc741bd2260a9b
BLAKE2b-256 5108dc2a6a6e034da469091121df1cd6f63bf72d8abf876bb7525f9d1c685dd0

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