Learn how to handle OpenAI API rate limits (429) and quota errors. Covers error types, exponential backoff, Python library exceptions, and troubleshooting steps for production applications.
This guide covers everything you need to know about OpenAI API rate limits and quota errors. It is for developers who use the OpenAI API and want to understand, prevent, and handle the most common HTTP 429 errors and related issues. You will learn the difference between rate limits and quota limits, how to interpret error messages, and how to implement robust retry logic with exponential backoff.
Before you begin, make sure you have the following:
pip install openai.The OpenAI API uses two distinct types of limits that both produce a 429 HTTP status code, but they mean different things and require different solutions.
A rate limit error means you are sending requests too quickly. The API has a maximum number of requests or tokens it will accept from you within a given time window (usually per minute). According to the official documentation, this can happen if:
The solution is to pace your requests. The official documentation recommends implementing a backoff mechanism or retry logic that respects the rate limit and the response headers. You can read more in the Rate limit guide.
A quota error means you have run out of credits or hit your maximum monthly spend. The official documentation states this can happen if:
The solution is to buy more credits or increase your limits. You can view your maximum usage limit on the limits page. If you are on a free plan, consider upgrading to a paid plan to get higher limits. Reach out to your organization owner to increase the budgets for your project.
The OpenAI API returns specific error messages that tell you exactly which limit you have hit. Here is how to interpret them, based on the official documentation.
This is the standard rate limit error. The official documentation says: "You are sending requests too quickly." The solution is to pace your requests and read the Rate limit guide.
This is the quota error. The official documentation says: "You have run out of credits or hit your maximum monthly spend." The solution is to buy more credits or learn how to increase your limits.
This is a server-side error, not a rate limit error, but it is often confused with one. The official documentation says: "Our servers are experiencing high traffic." The solution is to retry your request after a brief wait, using an exponential backoff strategy. Check the status page for any ongoing incidents.
This error can occur with Pay-As-You-Go models, which are shared across all OpenAI users. The official documentation explains that it indicates your traffic has significantly increased, overloading the model and triggering temporary throttling to maintain service stability. The solution is to reduce your request rate to its original level, keep it stable for at least 15 minutes, and then gradually ramp it up. Maintain a consistent traffic pattern to minimize the likelihood of throttling. Consider upgrading to the Scale Tier for guaranteed capacity and performance.
The official documentation provides a code snippet for handling errors programmatically using the OpenAI Python library. This is the recommended approach for production applications.
The following code shows how to catch different types of errors and handle them appropriately. The official documentation advises using exponential backoff for rate limit errors.
import openai
from openai import OpenAI
client = OpenAI()
try:
# Make your OpenAI API request here
response = client.responses.create(
model="gpt-5.6",
input="Hello world"
)
except openai.APIError as e:
# Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.APIConnectionError as e:
# Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.RateLimitError as e:
# Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
Explanation of the code:
openai.APIError: This is the base class for all API errors. Catching it first is a good fallback for any unexpected API error.openai.APIConnectionError: This indicates a network issue, such as a DNS resolution failure or a refused connection. The official documentation suggests checking your network settings, proxy configuration, SSL certificates, or firewall rules.openai.RateLimitError: This is the specific error for hitting a rate limit. The official documentation explicitly recommends using exponential backoff for this error.Exponential backoff is a standard error-handling strategy where you wait an increasing amount of time between retries. The official documentation recommends this approach for rate limit errors and server overload errors (503).
Here is a more complete example that implements exponential backoff with a maximum number of retries:
import openai
from openai import OpenAI
import time
import random
client = OpenAI()
def make_request_with_retry(max_retries=5, base_delay=1):
for attempt in range(max_retries):
try:
response = client.responses.create(
model="gpt-5.6",
input="Hello world"
)
return response
except openai.RateLimitError as e:
if attempt == max_retries - 1:
raise # Re-raise the last error
# Calculate delay with exponential backoff and jitter
delay = base_delay * (2 ** attempt) + random.uniform(0, 1)
print(f"Rate limit hit. Retrying in {delay:.2f} seconds...")
time.sleep(delay)
except openai.APIConnectionError as e:
if attempt == max_retries - 1:
raise
delay = base_delay * (2 ** attempt) + random.uniform(0, 1)
print(f"Connection error. Retrying in {delay:.2f} seconds...")
time.sleep(delay)
except openai.APIError as e:
# For other API errors, do not retry automatically
raise
response = make_request_with_retry()
print(response)
Why exponential backoff works:
Quota errors are different from rate limit errors. They indicate that you have exhausted your monthly usage limit or your prepaid credits. The official documentation provides the following steps to resolve quota errors:
Quota errors cannot be resolved by retrying. You must either increase your quota or wait until your quota resets (usually at the beginning of your billing cycle).

The official documentation lists several other HTTP errors that can occur and are sometimes mistaken for rate limit issues. Here is a quick reference.
This error means your authentication credentials are invalid. The official documentation lists these possible causes:
To resolve this, check that you are using the correct API key and organization ID in your request header. You can find your API key and organization ID in your account settings. If you are unsure, generate a new API key.
This error means the API key you are using is not correct. The official documentation lists these possible causes:
To resolve this, try clearing your browser's cache and cookies, then try again. Check that you are using the correct API key in your request header. If you are unsure, generate a new API key.
This error means your account is not part of an organization. The official documentation lists these possible causes:
To resolve this, you can either request a new organization or get invited to an existing one. To request a new organization, reach out to OpenAI via help.openai.com. Existing organization owners can invite you to join their organization via the Team page.
This error means your request IP does not match the configured IP allowlist for your project or organization. The solution is to send the request from the correct IP, or update your IP allowlist settings.
This error means you are accessing the API from an unsupported country, region, or territory. Please see the supported countries page for more information.
This is a server-side error. The official documentation says: "Issue on our servers." The solution is to retry your request after a brief wait and contact OpenAI if the issue persists. Check the status page.
This is a server-side error indicating high traffic. The official documentation says: "Our servers are experiencing high traffic." The solution is to retry your requests after a brief wait, using an exponential backoff strategy. Check the status page for updates.

The official OpenAI Python library defines specific exception classes that map to HTTP errors. Understanding these helps you write more precise error handling.
| Error Type | HTTP Status | Cause | Solution |
|---|---|---|---|
APIConnectionError | N/A | Issue connecting to our services. | Check your network settings, proxy configuration, SSL certificates, or firewall rules. |
APITimeoutError | N/A | Request timed out. | Retry your request after a brief wait and contact us if the issue persists. |
AuthenticationError | 401 | Your API key or token was invalid, expired, or revoked. | Check your API key or token and make sure it is correct and active. You may need to generate a new one. |
BadRequestError | 400 | Your request was malformed or missing some required parameters. | Read the error message carefully. Check the API reference for the specific method you are calling. |
ConflictError | 409 | The resource was updated by another request. | Try to update the resource again and ensure no other requests are trying to update it. |
InternalServerError | 500 | Issue on our side. | Retry your request after a brief wait and contact us if the issue persists. |
NotFoundError | 404 | Requested resource does not exist. | Ensure you are using the correct resource identifier. |
PermissionDeniedError | 403 | You don't have access to the requested resource. | Ensure you are using the correct API key, organization ID, and resource ID. |
RateLimitError | 429 | You have hit your assigned rate limit. | Pace your requests. Read more in the Rate limit guide. |
UnprocessableEntityError | 422 | Unable to process the request despite the format being correct. | Please try the request again. |
The official documentation provides detailed guidance for each error type. Here are the key points for the most common ones.
An APIConnectionError indicates that your request could not reach OpenAI's servers or establish a secure connection. The official documentation suggests checking:
An APITimeoutError indicates that your request took too long to complete. The official documentation suggests:
An AuthenticationError indicates that your API key or token was invalid, expired, or revoked. The official documentation suggests:
A BadRequestError (formerly InvalidRequestError) indicates that your request was malformed or missing required parameters. The official documentation suggests:
An InternalServerError indicates something went wrong on OpenAI's side. The official documentation suggests:
A RateLimitError indicates you have hit your assigned rate limit. The official documentation suggests:
This section covers common failure modes and how to diagnose them, based on the official documentation and community best practices.
This can happen if you are sharing your API key with other users or applications. The official documentation notes that "limits are applied per organization and not per user." Check the usage of the rest of your team, as this will contribute to the limit. Consider creating separate API keys for different applications or users.
This error is specific to Pay-As-You-Go models. The official documentation says to reduce your request rate to its original level, keep it stable for at least 15 minutes, and then gradually ramp it up. If you need guaranteed capacity, consider upgrading to the Scale Tier.
This can happen if your API key has been revoked or if you are using an API key that belongs to a different organization or project. The official documentation suggests generating a new API key and ensuring you are using the correct organization ID in your request header.
This can be due to network issues or heavy load on OpenAI's servers. The official documentation suggests waiting a few seconds and retrying. If the issue persists, check your network settings and the status page.
You can check your API usage statistics from your account dashboard. The official documentation also points to the limits page where you can view your maximum usage limit.
If you encounter persistent errors, the official documentation recommends providing the following information to OpenAI support via chat:
Once you have mastered basic error handling, consider exploring these advanced topics mentioned in the official documentation:
Learn how to use the OpenAI Batch API to cut costs by 50% for bulk processing tasks. Covers setup, request formatting, job creation, monitoring, error handling, and troubleshooting.
Learn how to write prompts for ChatGPT that reliably generate working code. Covers core concepts, setup, and specific patterns for different coding tasks.
Learn how to use the OpenAI Vision API to analyze images with GPT models. Covers setup, sending images via URL, Base64, or file ID, controlling detail levels, cost calculation, and troubleshooting.
Learn how to stream ChatGPT responses in web applications using the OpenAI API. This guide covers setup, implementation in JavaScript and Python, event handling, and troubleshooting for real-time text generation.
Learn how to use OpenAI's text embedding models for semantic search, clustering, recommendations, and classification. This guide covers concepts, setup, API usage, dimension reduction, and practical tips from official documentation and community experience.
Learn how to use OpenAI Structured Outputs to guarantee JSON schema conformance from GPT models. Covers function tool definitions, strict mode, tool call handling, and best practices for both Chat Completions and Responses APIs.
Workflows from the Neura Market marketplace related to this ChatGPT resource