High severity beginner · Fix: 2-5 min

OpenAIError

openai.OpenAIError (model deprecated migration error)

What this error means
This error occurs when you attempt to use an OpenAI model that has been deprecated and is no longer supported by the API.

Stack trace

traceback
openai.OpenAIError: The model you requested is deprecated and no longer available. Please migrate to a supported model as per the latest OpenAI API documentation.
QUICK FIX
Change your model parameter to a supported model like 'gpt-4o' in your OpenAI client calls immediately.

Why it happens

OpenAI periodically deprecates older models to improve service quality and security. When your code references a deprecated model name, the API rejects the request with this error. This forces developers to migrate to newer, supported models.

Detection

Monitor API error responses for OpenAIError messages indicating model deprecation, and log the model name used in requests to identify outdated references before failures occur.

Causes & fixes

1

Using a model name that OpenAI has deprecated and removed from the API.

✓ Fix

Update your code to use a currently supported model such as 'gpt-4o' or 'gpt-4o-mini' as documented in the latest OpenAI SDK.

2

Hardcoded model names in legacy code or configuration files that have not been updated.

✓ Fix

Replace all hardcoded deprecated model names with environment variables or config entries pointing to supported models, and verify usage throughout your codebase.

3

Using an outdated OpenAI SDK version that defaults to deprecated models.

✓ Fix

Upgrade the OpenAI Python SDK to the latest version and explicitly specify a supported model in your client calls.

Code: broken vs fixed

Broken - triggers the error
python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])

response = client.chat.completions.create(
    model='gpt-4',  # deprecated model triggers error
    messages=[{'role': 'user', 'content': 'Hello'}]
)
print(response)
Fixed - works correctly
python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])

response = client.chat.completions.create(
    model='gpt-4o',  # updated to supported model
    messages=[{'role': 'user', 'content': 'Hello'}]
)
print(response)  # fixed: uses supported model
Updated the model parameter from deprecated 'gpt-4' to supported 'gpt-4o' to comply with current OpenAI API requirements.

Workaround

Catch OpenAIError exceptions, detect deprecated model messages, and programmatically switch to a fallback supported model before retrying the request.

Prevention

Regularly audit your code and dependencies for deprecated model usage and adopt environment-driven model configuration to enable seamless updates without code changes.

Python 3.9+ · openai >=1.0.0 · tested on 1.5.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.