Handling 429 rate limits with random exponential backoff
Answer: When you call an API repeatedly you may see 429: 'Too Many Requests' or RateLimitError. One easy mitigation is to retry requests automatically with a random exponential backoff: sleep, retry, and increase the sleep length each time until success or a maximum number of retries.
Rules of thumb (OpenAI cookbook)
- Failed requests also count toward the per-minute limit, so resending nonstop won't work.
- If you hit RPM limits but still have TPM capacity, consider batching multiple tasks into each request.
Tenacity recipes
@retry(wait=wait_random_exponential(multiplier=1, max=60))randomly waits up to 2^x seconds, capped at 60; exponentially increasing jitter helps minimise collisions.stop=stop_after_attempt(7)orstop=stop_after_delay(10)sets a boundary.retry=retry_if_exception_type(IOError)retries only matching errors.
See also
- ao-retries-sdk-defaults
- ao-structured-instructor-validation-retries
- ao-batch-apis-openai-and-anthropic
Claims
- id: C1 claim: Retry with random exponential backoff. source: S1 evidence: "retry requests with a random exponential backoff"
- id: C2 claim: Failed requests count toward the limit. source: S1 evidence: "unsuccessful requests contribute to your per-minute limit"
- id: C3 claim: Jitter helps minimise collisions. source: S2 evidence: "exponentially increasing jitter helps minimise collisions"
Sources
- [S1] How to handle rate limits. openai/openai-cookbook (GitHub). https://github.com/openai/openai-cookbook/blob/main/examples/How_to_handle_rate_limits.ipynb . License: MIT. Accessed 2026-11-16.
- [S2] Tenacity documentation. jd/tenacity (GitHub). https://github.com/jd/tenacity/blob/main/doc/source/index.rst . License: Apache-2.0. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: openai/openai-cookbook (GitHub), How to handle rate limits, MIT (https://raw.githubusercontent.com/openai/openai-cookbook/main/LICENSE). Copyright (c) 2025 OpenAI; jd/tenacity (GitHub), Tenacity documentation, Apache-2.0 (https://raw.githubusercontent.com/jd/tenacity/main/LICENSE). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: openai/openai-cookbook (GitHub), How to handle rate limits, MIT (https://raw.githubusercontent.com/openai/openai-cookbook/main/LICENSE). Copyright (c) 2025 OpenAI; jd/tenacity (GitHub), Tenacity documentation, Apache-2.0 (https://raw.githubusercontent.com/jd/tenacity/main/LICENSE).
Cite this
iinventedlight. 2026. "Handling 429 rate limits with random exponential backoff." iinventedlight Library, iil:note:4p4n5ter, version of 2026-11-16. https://iinventedlight.com/library/notes/ao-retries-exponential-backoff/. License: CC-BY-4.0.
@misc{iil_note_4p4n5ter,
author = {{iinventedlight}},
title = {{Handling 429 rate limits with random exponential backoff}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/ao-retries-exponential-backoff/},
note = {Permanent ID iil:note:4p4n5ter. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/ao-retries-exponential-backoff.md.