Skip to main content

A wrapper engine to enforce request-based, token-based, and concurrency-based limits on kani engines.

Project description

kani-ratelimits

This is a simple, small package to to enforce request-per-minute (RPM), token-per-minute (TPM), and/or max-concurrency ratelimits before making requests to an underlying engine.

Installation

pip install kani-ratelimits

Usage

from kani.ext.ratelimits import RatelimitedEngine

# limit requests to 10 req/min and 30k tokens/min
inner_engine = ...  # your engine here, e.g. `OpenAIEngine(..., model="gpt-4")`
engine = RatelimitedEngine(inner_engine, rpm_limit=10, tpm_limit=30_000)

The RatelimitedEngine takes the following parameters:

  • engine: The engine to wrap.
  • max_concurrency (int): The maximum number of concurrent requests to serve at once (default unlimited).
  • rpm_limit (float): The maximum number of requests to serve per rpm_period (default unlimited).
  • rpm_period (float): The duration, in seconds, of the time period in which to limit the rate. Note that up to rpm_limit requests are allowed within this time period in a burst (default 60s).
  • tpm_limit (float): The maximum number of tokens to send in requests per tpm_period (default unlimited).
  • tpm_period (float): The duration, in seconds, of the time period in which to limit the rate. Note that up to tpm_limit tokens are allowed within this time period in a burst (default 60s).

The ratelimiter will ensure that all conditions are met before forwarding the request to the wrapped engine.

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

kani_ratelimits-1.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

kani_ratelimits-1.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file kani_ratelimits-1.1.0.tar.gz.

File metadata

  • Download URL: kani_ratelimits-1.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kani_ratelimits-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e90e14e54eb55698ca941391cfe7eea0a03089083f7e53fb58e2bb832da4615c
MD5 f7804720709f287e9ce4f3f9e10b18e2
BLAKE2b-256 2a729b0e4294508dda11a4ba9b3c72b270afb240cdd5a54e7b88b373c68bcf42

See more details on using hashes here.

Provenance

The following attestation bundles were made for kani_ratelimits-1.1.0.tar.gz:

Publisher: pythonpublish.yml on zhudotexe/kani-ratelimits

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kani_ratelimits-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for kani_ratelimits-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f42124a84ebc1e0d9ba451bd3432ee1554bc21f11d9f522b200a96ceef857187
MD5 b4f168959de71d14513e6bd0aa9d1f03
BLAKE2b-256 52ab33f50ff5da8c4be55443f956e4475577d95dce2cb1d5487f0a14d5671c64

See more details on using hashes here.

Provenance

The following attestation bundles were made for kani_ratelimits-1.1.0-py3-none-any.whl:

Publisher: pythonpublish.yml on zhudotexe/kani-ratelimits

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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