Skip to content

rate_limiter

diapason.security.rate_limiter

Rate limiter -- token bucket algorithm for per-agent/per-tool throttling.

RateLimitConfig dataclass

Configuration for rate limiting.

__post_init__()

Reject configurations that would disable or break enforcement.

RateLimiter

Rate limiter with per-key token buckets.

Keys are typically "agent_id:tool_name" or just "agent_id".

check(key)

Check if request is allowed for key — always via Rust backend.

reset(key=None)

Reset rate limit state for a key or all keys — always via Rust backend.

TokenBucket

Thread-safe token bucket for rate limiting.

available property

Current available tokens (approximate).

consume(tokens=1)

Try to consume tokens. Returns (allowed, wait_seconds).