OpenAI API 500 "The server had an error": retry and fix
OpenAI API 500 "The server had an error" is OpenAI-side. The SDK retries twice, quits in a second, so raise retries, check status, then contact support.
500 - The server had an error while processing your requestOpenAI's servers failed while processing your request. The official error table lists the cause as "Issue on our servers" and the fix as waiting briefly and retrying. It is not an authentication or quota error, so first check how retries are already behaving. If one particular request keeps returning 500, step 5 covers sending it to support so they can tell whether that request is the trigger.
[1] Do not confuse it with neighboring errors. They look alike, but the official table gives each a different action.
| Response | Cause (official table) | What to do |
|---|---|---|
| 500 The server had an error while processing your request | Issue on OpenAI's servers | Retry after a brief wait; status page and support if it persists |
| 503 Model temporarily overloaded | The requested model is temporarily overloaded | Follow Retry-After and retry (503 guide) |
| 429 Rate limit reached for requests | You are sending requests too quickly | Slow down (429 TPM) |
| 429 Credit balance exhausted and similar | Credits or spend limits | Retrying will not help (quota) |
The Python library raises InternalServerError for both 500 and 503. The class name cannot tell them apart, so check e.status_code.
[2] Check whether the failure already survived retries. The official SDK resends responses with status 500 and above, twice by default. The test attached openai 3.49.0 to a local mock server that only returns 500 and called chat.completions.create (no real API calls). The second argument of client.py is a trial label; a third argument, when present, sets max_retries.
$ python client.py always500 d1InternalServerError status=500 after 1.3s$ python client.py always500 z0 0InternalServerError status=500 after 0.0s$ python client.py once500 o1success 'ok' after 0.4sThe server-side log follows. The value in parentheses is the gap since the previous request of the same trial.
always500/d1 request 1 (first) -> 500always500/d1 request 2 (+0.39s) -> 500always500/d1 request 3 (+0.85s) -> 500That is one first attempt plus two retries, three requests in all, with gaps of roughly 0.4 and 0.9 seconds. Across five repeats the first gap ranged from 0.38 to 0.49 seconds and the second from 0.78 to 0.98 seconds. If the fault clears in between, your code never sees the error (once500: the second request got a 200). If it does not, the exception surfaces after about 1.3 seconds. A 500 in your app log therefore means the SDK has already held on for over a second. With max_retries=0 it fails at once, in 0.0 seconds.
[3] Raise the retry count to ride out short faults. The SDK starts at 0.5 seconds, doubles the wait each time, and stops growing at 8 seconds (source constants INITIAL_RETRY_DELAY = 0.5, MAX_RETRY_DELAY = 8.0). Here is max_retries=5.
$ python client.py always500 z5 5InternalServerError status=500 after 14.0salways500/z5 request 1 (first) -> 500always500/z5 request 2 (+0.40s) -> 500always500/z5 request 3 (+0.96s) -> 500always500/z5 request 4 (+1.87s) -> 500always500/z5 request 5 (+3.17s) -> 500always500/z5 request 6 (+7.56s) -> 500The gaps ran slightly under 0.5, 1, 2, 4, and 8 seconds, and the SDK gave up after 14 seconds in total. To apply it everywhere, create the client with OpenAI(max_retries=5); for a single call, use client.with_options(max_retries=5).chat.completions.create(...). When an outage lasts, more retries will not help; queue work that can wait and process it later.
[4] See whether a response header changes the retries. The SDK reads x-should-retry and Retry-After. When the mock server attaches them to its 500, this happens.
$ python client.py noretry500 n1InternalServerError status=500 after 0.0s$ python client.py ra500 r1InternalServerError status=500 after 4.0snoretry500/n1 request 1 (first) -> 500ra500/r1 request 1 (first) -> 500ra500/r1 request 2 (+2.00s) -> 500ra500/r1 request 3 (+2.00s) -> 500With x-should-retry: false it fails immediately without retrying; with Retry-After: 2 it waits 2 seconds each time instead of the default gaps. It is unconfirmed whether real OpenAI 500 responses carry these headers. If retries look shorter or longer than expected, print the response headers first.
[5] If it keeps happening, open status.openai.com and look for an active incident. The docs say to follow the updates and wait until it is resolved before retrying. If there is no incident and the same request keeps returning 500, contact support through the chat at OpenAI Help. The docs ask for five things.
| Provide | Note |
|---|---|
| The model you were using | |
| The error message and code | Copy them from the failed response or exception (in Python, e.message and e.code). The output block at the top is the docs table heading, not a real response |
| The request data and headers you sent | Remove the API key before sending |
| The timestamp and timezone of the request | |
| Any other details that help diagnosis |
[6] If your app adds its own retry layer, count how it multiplies with the SDK's. Three outer attempts on top of the SDK default can send up to nine requests. Use one layer and set max_retries=0 on the other.