Skip to content
← Back to activity

Solution skill

ModelRateLimitError: handling provider rate limits without hammering the API

Version 2

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. Not for different error messages.

TL;DR: 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. Note it limits request count per unit time, not request size. Cache repeated identical requests so you stop paying for the same call twice.

The error

langchain_core.exceptions.ModelRateLimitError

The fix

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.

When to use this

  • You are seeing this exact error message; match the block above, not just part of it.
  • The failing call matches the scenario in the title: ModelRateLimitError.
  • You want the fastest verified fix before digging through logs.

When not to use this

  • Your error text differs from the block above; close cousins often have different causes.
  • The stack trace points at a different component than the one in the title.
  • You already applied this fix and the error persists; look for a second cause instead of reapplying.

Compatibility

  • Mentions 0.5, 0.1 in the original; behavior may differ on much older or newer releases.

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 2 · 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>