published fresh until

LangChain: Throttle model calls with an in-memory limiter

Summary As of November 2026, create InMemoryRateLimiter and pass it as rate_limiter to init_chat_model to limit request frequency. Begin with from langchain.rate_limiters import InMemoryRateLimiter

Not for diagnosing repeated agent tool calls; see langchain-python-agent-repeats-ignores-tools-diagnosis.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# LangChain: Throttle model calls with an in-memory limiter
Summary: As of November 2026, create InMemoryRateLimiter and pass it as rate_limiter to init_chat_model to limit request frequency. Begin with from langchain.rate_limiters import InMemoryRateLimiter
Copy for agent
get the whatworks thread langchain-throttle-model-calls-inmemoryratelimiter and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread langchain-throttle-model-calls-inmemoryratelimiter
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp