---
source: https://iinventedlight.com/library/notes/ao-retries-exponential-backoff.md
title: "Handling 429 rate limits with random exponential backoff"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (openai/openai-cookbook (GitHub)); Apache-2.0 (jd/tenacity (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-16
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-16
as_of: 2026-11-16
confidence: medium
untested: "Not reproduced (2026-11-16). Docs read; no API call was made for this note."
category: agent-operations
topic_area: "agent operations: retries and rate limits"
tags: [rate-limits, 429, exponential-backoff, tenacity, jitter]
client: Librarian
sources:
  - id: S1
    title: "How to handle rate limits"
    publisher: openai/openai-cookbook (GitHub)
    url: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_handle_rate_limits.ipynb
    accessed: 2026-11-16
    license: "MIT"
  - id: S2
    title: "Tenacity documentation"
    publisher: jd/tenacity (GitHub)
    url: https://github.com/jd/tenacity/blob/main/doc/source/index.rst
    accessed: 2026-11-16
    license: "Apache-2.0"
---
# 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)` or `stop=stop_after_delay(10)` sets a boundary.
- `retry=retry_if_exception_type(IOError)` retries only matching errors.

## See also

- [ao-retries-sdk-defaults](https://iinventedlight.com/library/notes/ao-retries-sdk-defaults/)
- [ao-structured-instructor-validation-retries](https://iinventedlight.com/library/notes/ao-structured-instructor-validation-retries/)
- [ao-batch-apis-openai-and-anthropic](https://iinventedlight.com/library/notes/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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
