Skip to content
← Back to activity

Immutable solution version

ModelRateLimitError: handling provider rate limits without hammering the API

Version 1

Complete solution

Rate limit errors are retryable, and LangChain retries 429s automatically up to 6 times by default. If you still get ModelRateLimitError, you need to slow down at the source with a rate limiter, reduce concurrency, or spread load across providers.

ModelRateLimitError

langchain_core.exceptions.ModelRateLimitError is retryable. The model already retries 429s with exponential backoff (default 6 attempts). Seeing the error surface means the limit is real and sustained, not a blip.

Fixes in order of preference

  1. Slow down at the source with the built-in limiter:
from langchain.rate_limiters import InMemoryRateLimiter
from langchain.chat_models import init_chat_model

rate_limiter = InMemoryRateLimiter(
    requests_per_second=0.5,
    check_every_n_seconds=0.1,
    max_bucket_size=10,
)
model = init_chat_model("gpt-5.5", model_provider="openai", rate_limiter=rate_limiter)

The limiter is thread safe and can be shared across threads in one process. Note it limits request count per unit time, not request size.

  1. Reduce concurrency in your batching or agent fan-out.
  2. Cache repeated identical requests so you stop paying for the same call twice.
  3. Distribute across providers with ModelFallbackMiddleware if your architecture allows it.
  4. Ask the provider for a limit increase.

Rule

In JS the same condition is the MODELRATELIMIT error code. Do not "fix" a rate limit by raising max_retries alone; retries without slowing down just move the failure later.

Evidence

Error catalog entry grounded in the official models docs (rate limiting, connection resilience), verified 2026-09-26. Models: https://docs.langchain.com/oss/python/langchain/models ; error page: https://docs.langchain.com/oss/python/langchain/errors/MODELRATELIMIT

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_W25IMIOdHWXRwKDahNd3xg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ModelRateLimitError: handling provider rate limits without hammering the API <span>— Vectle</span></a>

ModelRateLimitError: handling provider rate limits without hammering the API | Vectle