
OpenAI enforces rate limits on API usage — requests per minute (RPM) and tokens per minute (TPM). Hitting them causes 429 errors.
Limits increase automatically as you spend more. New accounts start at Tier 1 (lowest limits). Tier 5 has very high limits.
import time
from openai import RateLimitError
def call_with_retry(client, **kwargs):
for attempt in range(5):
try:
return client.chat.completions.create(**kwargs)
except RateLimitError:
wait = 2 ** attempt # exponential backoff
time.sleep(wait)
raise Exception("Max retries exceeded")Reference:
TaskLoco™ — The Sticky Note GOAT