For bot/messaging rate limiting (Telegram, Discord, Slack), see Bot Rate Limiting. This page covers LLM API rate limiting.
How It Works
Quick Start
How It Works
Token bucket algorithm: tokens refill atrequests_per_minute / 60 per second; each LLM call consumes one token. Under contention, callers wait until a token is available.
The limiter applies to both the initial LLM call and the follow-up after tool execution in streaming mode.
The rate limiter applies to every LLM call the agent issues — single-shot, streaming, tool-iteration and reflection turns, sync and async — so a per-model token budget is never spent on a path that bypasses throttling.
| Step | What happens |
|---|---|
| Refill | Tokens regenerate on elapsed time |
| Acquire | Caller reserves a token (thread-safe) |
| Wait | Sleeps or awaits when bucket is empty |
| Release | Automatic — rolling window, no explicit release |
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
max_rpm | int | None | Shorthand on ExecutionConfig |
requests_per_minute | int | None | Max requests per rolling 60s window |
tokens_per_minute | int | None | Token budget for TPM-quoted providers |
burst | int | 1 | Back-to-back requests before rate kicks in |
max_retry_delay | int | 120 | Max wait seconds when rate limited |
Best Practices
Match burst to your workload
Match burst to your workload
Low burst (1–5) smooths traffic; higher burst tolerates spiky demand.
Set tokens_per_minute for TPM limits
Set tokens_per_minute for TPM limits
Providers quote RPM and TPM — limiting only RPM can still trigger 429 errors.
Use async paths in async flows
Use async paths in async flows
agent.achat() calls acquire_async() automatically; avoid mixing sync and async limiters.CLI
Related
Thread Safety
Thread-safe chat history and caches
Concurrency
Limit parallel agent runs

