tessl install tessl/pypi-pyrate-limiter@3.9.0Python Rate-Limiter using Leaky-Bucket Algorithm for controlling request rates in applications with multiple backend storage options.
Agent Success
Agent success rate when using this tile
81%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.45x
Baseline
Agent success rate without this tile
56%
Build a diagnostic tool that monitors API rate limit violations and identifies which specific rate limits are being hit.
You need to create a rate monitoring system that tracks API requests and provides diagnostic information when rate limits are exceeded. The system should help developers understand which specific rate limit (per-second, per-minute, per-hour, etc.) is causing requests to be rejected.
The monitor should enforce multiple concurrent rate limits:
Implement a function monitor_api_request(user_id: str) -> dict that:
allowed (bool): whether the request was alloweduser_id (str): the user identifierfailing_limit (str or None): description of which rate limit was exceeded (e.g., "5 per second", "20 per minute", or None if allowed)@generates
def monitor_api_request(user_id: str) -> dict:
"""
Monitor an API request and check against rate limits.
Args:
user_id: Identifier for the user making the request
Returns:
Dictionary with keys:
- allowed (bool): Whether request was permitted
- user_id (str): The user identifier
- failing_limit (str|None): Description of exceeded limit or None
"""
passProvides rate limiting with failure diagnostics.