OpenAIError
openai.OpenAIError (fine-tuned model deprecated migration)
Stack trace
openai.OpenAIError: The fine-tuned model you are trying to use has been deprecated. Please migrate to the new fine-tuning API and update your model name accordingly.
at client.chat.completions.create (/path/to/your/code.py:45) Why it happens
OpenAI has deprecated older fine-tuned models and the associated API endpoints. When you call the API with an old fine-tuned model name or endpoint, the server rejects the request with this error. This forces developers to migrate to the new fine-tuning system and update their model references.
Detection
Monitor API error responses for OpenAIError messages indicating model deprecation. Log the model name and error details to identify deprecated fine-tuned models before production failures.
Causes & fixes
Using an old fine-tuned model name that OpenAI no longer supports
Migrate your fine-tuning jobs using OpenAI's new fine-tuning API and update your code to reference the new model names.
Calling deprecated fine-tuning endpoints instead of the current OpenAI API endpoints
Update your API calls to use the latest OpenAI SDK methods and endpoints for fine-tuned models.
Not updating environment variables or configuration after migrating fine-tuned models
Ensure your environment variables and config files reference the new fine-tuned model names and API keys if changed.
Code: broken vs fixed
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
response = client.chat.completions.create(
model="old-fine-tuned-model",
messages=[{"role": "user", "content": "Hello"}]
) # This line triggers the deprecated model error
print(response) import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
response = client.chat.completions.create(
model="new-fine-tuned-model",
messages=[{"role": "user", "content": "Hello"}]
) # Updated to new fine-tuned model name
print(response) Workaround
Catch the OpenAIError exception, log the deprecated model error, and fallback to a base instruction-tuned model until you complete the migration.
Prevention
Regularly check OpenAI's fine-tuning API announcements and update your fine-tuned models and API calls promptly to avoid using deprecated models.