RateLimiter class

Token-bucket rate limiter for API calls.

Tracks both requests-per-minute and tokens-per-minute to stay within Anthropic rate limits. Uses a sliding window approach.

Constructors

RateLimiter({int maxRequestsPerMinute = 50, int maxTokensPerMinute = 100000})

Properties

hashCode int
The hash code for this object.
no setterinherited
maxRequestsPerMinute int
final
maxTokensPerMinute int
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

checkLimit({int estimatedTokens = 0}) Duration
Check whether a request with estimatedTokens can proceed.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
recordRateLimit() Duration
Record a rate limit (429) response. Returns the recommended backoff.
recordRequest({int tokens = 0}) → void
Record that a request was made.
reset() → void
Reset rate limit tracking (e.g. after a long pause).
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited