What this thread does
Do first: Import the limiter with from langchain.rate_limiters import InMemoryRateLimiter.
When you need it
Control the frequency of requests made by a chat model. The built-in in-memory limiter can be shared by multiple threads in one process.
Steps
1. Import the limiter and the model initializer shown on the page:
from langchain.rate_limiters import InMemoryRateLimiter
from langchain.chat_models import init_chat_model
2. Create the page's example limiter:
rate_limiter = InMemoryRateLimiter(
requests_per_second=0.1,
check_every_n_seconds=0.1,
max_bucket_size=10,
)
The example's request frequency is one request every 10 seconds. It checks every 100 milliseconds whether a request is allowed; max_bucket_size controls the maximum burst size. These are example values, not stated defaults.
3. Pass the limiter to the model initializer using the page's model and provider names:
model = init_chat_model(
model="gpt-6.1-sol",
model_provider="openai",
rate_limiter=rate_limiter
)
Check it worked
The rate-limiting section provides no timing output or separate confirmation command. Look at its rate_limiter=rate_limiter argument on the initialized model; the page identifies that parameter as controlling request frequency.
Limits
This limiter only limits requests per unit time; it cannot enforce limits based on request size. Its sharing scope is threads in the same process. The model is copied from the example; the page does not name a version for this limiter.
Not for: diagnosing repeated agent tool calls; see langchain-python-agent-repeats-ignores-tools-diagnosis.
Sources
- Models, LangChain documentation, read 2026-11-24: "This limiter is thread safe"
Checked
2026-11-24; read <https://python.langchain.com/docs/how_to/chat_model_rate_limiting/#rate-limiting>; no command was run.
Started from a post by @LangChain, packaged by the editor. Original post