OpenAIError
openai.OpenAIError (Model not found)
Stack trace
openai.OpenAIError: The model `ft:your-org:your-model-id` does not exist or is not accessible.
at openai.api_requestor.APIRequestor._handle_error_response (/path/to/openai/sdk)
at openai.api_requestor.APIRequestor.request (/path/to/openai/sdk)
at openai.client.chat.completions.create (/path/to/openai/sdk)
at main.py:15 Why it happens
This error happens because the fine-tuned model ID provided in the API call is incorrect, deleted, or belongs to a different organization. The OpenAI API cannot find or access the model resource under your credentials.
Detection
Check for OpenAIError exceptions when calling chat completions with a fine-tuned model ID, and log the model ID used to verify correctness before retrying.
Causes & fixes
The fine-tuned model ID is misspelled or incorrect in the API call.
Verify and correct the fine-tuned model ID string exactly as shown in your OpenAI dashboard or fine-tuning logs.
The fine-tuned model was deleted or is no longer available.
Check your OpenAI account dashboard to confirm the model exists; if deleted, retrain or restore the fine-tuned model.
Your API key belongs to a different organization than the fine-tuned model's owner.
Use an API key from the organization that owns the fine-tuned model or request access to that model.
Code: broken vs fixed
import os
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="ft:wrong-org:nonexistent-model",
messages=[{"role": "user", "content": "Hello"}]
) # This line triggers the model not found error import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
# Corrected model ID from your OpenAI fine-tuning dashboard
correct_model_id = os.environ.get("OPENAI_FINE_TUNED_MODEL")
response = client.chat.completions.create(
model=correct_model_id, # Fixed: use correct fine-tuned model ID from env
messages=[{"role": "user", "content": "Hello"}]
)
print(response) Workaround
Catch the OpenAIError exception, log the model ID used, and fallback to a base model like 'gpt-4o-mini' temporarily until the fine-tuned model issue is resolved.
Prevention
Always store and retrieve fine-tuned model IDs from a centralized config or environment variable, and verify model existence via the OpenAI dashboard before deployment.