BaseRateLimiter
langchain_core.rate_limiters.
Usage of the base limiter is through the acquire and aacquire methods depending on whether running in a sync or async context.
Implementations are free to add a timeout parameter to their initialize method to allow users to specify a timeout for acquiring the necessary tokens when using a blocking call.
Current limitations
- Rate limiting information is not surfaced in tracing or callbacks. This means that the total time it takes to invoke a chat model will encompass both the time spent waiting for tokens and the time spent making the request.
Methods
acquire
blocking is set to True.
If blocking is set to False, the method will immediately return the result of the attempt to acquire the tokens.
If
True, the method will block until the tokens are available. If False, the method will return immediately with the result of the attempt.True if the tokens were successfully acquired, False otherwise.aacquire
blocking is set to True.
If blocking is set to False, the method will immediately return the result of the attempt to acquire the tokens.
If
True, the method will block until the tokens are available. If False, the method will return immediately with the result of the attempt.True if the tokens were successfully acquired, False otherwise.InMemoryRateLimiter
Current limitations
- The rate limiter is not designed to work across different processes. It is an in-memory rate limiter, but it is thread safe.
- The rate limiter only supports time-based rate limiting. It does not take into account the size of the request or any other factors.
The number of tokens to add per second to the bucket. The tokens represent “credit” that can be used to make requests.
Check whether the tokens are available every this many seconds. Can be a float to represent fractions of a second.
The maximum number of tokens that can be in the bucket. Must be at least
1. Used to prevent bursts of requests.Example
Methods
Inheritsacquire and aacquire methods from BaseRateLimiter.