InvalidRequestError
openai.error.InvalidRequestError (fine-tuned model not found suffix)
Stack trace
openai.error.InvalidRequestError: The fine-tuned model 'ft-model-name-suffix' was not found. Please verify the model suffix and try again.
Why it happens
OpenAI fine-tuned models require the exact model suffix returned after fine-tuning. If you specify a suffix that does not exist or is mistyped, the API returns this error indicating the model cannot be found. This often happens when the suffix is omitted, misspelled, or the fine-tuning job has not completed successfully.
Detection
Check for InvalidRequestError exceptions when calling the fine-tuned model. Log the model suffix used and verify it matches the suffix returned by the fine-tuning API before making requests.
Causes & fixes
Using an incorrect or incomplete fine-tuned model suffix in the model parameter.
Retrieve the exact fine-tuned model suffix from the fine-tuning job response or list models API and use it verbatim in your requests.
Attempting to use a fine-tuned model before the fine-tuning job has completed.
Wait for the fine-tuning job status to be 'succeeded' before using the model suffix in API calls.
Passing the base model name instead of the fine-tuned model suffix.
Ensure you use the full fine-tuned model name (usually starting with 'ft-') returned by the fine-tuning process, not the base model like 'gpt-4o-mini'.
Code: broken vs fixed
import os
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o-mini", # Incorrect: base model used instead of fine-tuned suffix
messages=[{"role": "user", "content": "Hello"}]
) # This line triggers the error import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
response = client.chat.completions.create(
model="ft-abc123def456ghi789", # Fixed: exact fine-tuned model suffix
messages=[{"role": "user", "content": "Hello"}]
)
print(response) Workaround
If you cannot retrieve the fine-tuned model suffix immediately, list all available models via the API and programmatically select the correct fine-tuned model name before making requests.
Prevention
Always store and use the fine-tuned model suffix returned by the fine-tuning API job completion. Automate validation of model names before usage to prevent typos or premature calls.