OpenAI API calls fail with InternalServerError 500 or 503
Fix it fast
Most common cause, 1 of 3A transient fault on OpenAI's servers (500)
Allow more retries for calls that can safely run again, either on the client or for one call with with_options, and keep the request ID of every failure.
client = OpenAI(max_retries=5)
# or only for this call:
response = client.with_options(max_retries=5).responses.create(
model="gpt-5.5", input=prompt
)
print(response._request_id)Short answer
openai.InternalServerError with The server had an error while processing your request (500), or a 503 for a temporarily overloaded model, is a failure on OpenAI's side that the Python SDK raises after its two automatic retries. Retry later with backoff, raise max_retries, wait out Retry-After on a 503, and give support the request ID if it persists. Applies to openai 3.57.
Which cause do you have?
Catch the status error once and print the status code, the request ID and any Retry-After header. A 500 points to the first cause, a 503 to the second, and an error that arrives instantly from a client with retries turned off to the third.
import openai
from openai import OpenAI
client = OpenAI()
try:
client.responses.create(model="gpt-5.5", input="ping")
except openai.APIStatusError as exc:
print(exc.status_code, exc.request_id)
print(exc.response.headers.get("retry-after"))Then find the line you see in this list and open its fix:
- 1A transient fault on OpenAI's servers (500)
status_code is 500 with The server had an error while processing your request, and the same call succeeds a few minutes later - 2The model is temporarily overloaded (503)
status_code is 503, and the response may carry a retry-after header - 3Automatic retries are switched off in the client
The error is raised at once, with no delay, and the client is built with max_retries=0
What does the error look like?
openai.InternalServerErrorThe server had an error while processing your requestModel temporarily overloaded
Cause 1 of 3
A transient fault on OpenAI's servers (500)
You seestatus_code is 500 with The server had an error while processing your request, and the same call succeeds a few minutes later
Check
OpenAI's error-code guide lists 500, The server had an error while processing your request, as an issue on its servers, and asks you to retry after a brief wait. The SDK maps every status of 500 and above to InternalServerError and retries those twice with a short exponential backoff before raising, so an error that reaches your code has usually failed three times in quick succession.
print(exc.status_code) # 500Fix
Allow more retries for calls that can safely run again, either on the client or for one call with with_options, and keep the request ID of every failure.
client = OpenAI(max_retries=5)
# or only for this call:
response = client.with_options(max_retries=5).responses.create(
model="gpt-5.5", input=prompt
)
print(response._request_id)Verify
A rerun of the same workload finishes, and any remaining failures in your log carry a request ID.
python job.pyConfirmed by developers.openai.com
Cause 2 of 3
The model is temporarily overloaded (503)
You seestatus_code is 503, and the response may carry a retry-after header
Check
The error-code guide describes 503 as the requested model being temporarily overloaded, and tells you to follow the Retry-After header when the response has one before trying again. The Python library raises InternalServerError for 503 as well, so code that catches only RateLimitError for overload handling never sees it.
print(exc.status_code, exc.response.headers.get("retry-after"))Fix
On a 503, wait as long as Retry-After says (a number of seconds), then retry; fall back to a fixed pause when the header is missing, and give up after a few attempts.
import time
def ask(prompt, attempts=3):
for attempt in range(attempts):
try:
return client.responses.create(model="gpt-5.5", input=prompt)
except openai.InternalServerError as exc:
if exc.status_code != 503 or attempt == attempts - 1:
raise
time.sleep(float(exc.response.headers.get("retry-after", "5")))Verify
During an overload the job slows down instead of failing, and each request finishes once the model has capacity again.
python job.pyConfirmed by developers.openai.com
Cause 3 of 3
Automatic retries are switched off in the client
You seeThe error is raised at once, with no delay, and the client is built with max_retries=0
Check
The SDK retries connection errors, 408, 409, 429 and 5xx responses twice by default, but max_retries=0 disables that. A client configured that way, often copied from a test setup, passes every short server fault straight to the caller, so 500 errors show up far more often than they need to.
grep -rn "max_retries" .Fix
Remove max_retries=0 from production clients, or set a value that matches how long the caller can wait.
client = OpenAI() # default: 2 retries
client = OpenAI(max_retries=4) # more patience for batch jobsVerify
Short server hiccups no longer reach your logs as errors; only faults that outlast the retries do.
python job.pyConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Write every request so it can be repeated safely, then let the SDK retry and add a slower retry loop around batch work.
- Log exc.request_id and status_code for each APIStatusError; that pair is what support needs when a 500 keeps coming back.
- Catch openai.InternalServerError separately from RateLimitError, because 503 overload arrives as the former even though it calls for backing off.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.