AI / Core OpenAI Codex Application Fundamentals Interview Questions
What are rate limits in the OpenAI API and how do you handle them in production?
OpenAI enforces rate limits to ensure fair access and prevent abuse. Limits are applied on three dimensions and vary by model and usage tier. Hitting rate limits returns a 429 Too Many Requests error.
| Dimension | Abbreviation | What it limits |
|---|---|---|
| Requests per minute | RPM | Number of API calls in 60 seconds |
| Tokens per minute | TPM | Total input + output tokens processed per 60 seconds |
| Requests per day | RPD | Total API calls in 24 hours (some lower tiers) |
import time import openai from openai import OpenAI client = OpenAI() # 1. Exponential backoff with jitter - handle 429 errors gracefully def call_with_retry(prompt: str, max_retries: int = 5): for attempt in range(max_retries): try: return client.responses.create( model="gpt-5.5", input=prompt, ) except openai.RateLimitError as e: if attempt == max_retries - 1: raise wait = (2 ** attempt) + (0.1 * attempt) # exponential + jitter print(f"Rate limited. Waiting {wait:.1f}s...") time.sleep(wait) # 2. The Python SDK retries automatically by default # Configure retry behaviour: client = OpenAI( max_retries=3, # default is 2 timeout=60.0, # request timeout in seconds ) # 3. Use the Batch API for large non-time-sensitive workloads # Batch processing: ~50% cost reduction, no rate limit impact response = client.batches.create( input_file_id="file-abc123", endpoint="/v1/responses", completion_window="24h", )
Tier progression: accounts start at Tier 1 with conservative limits. Limits automatically increase as spending grows (Tier 2 at $100 spend, Tier 3 at $500, etc.). For production workloads needing higher limits, contact OpenAI to request increases.
More Related questions...