OpenAIError
openai.OpenAIError (embedding model not found)
Stack trace
openai.OpenAIError: The model `text-embedding-xyz` does not exist
at openai.api_requestor.APIRequestor._handle_error_response (/path/to/sdk/requestor.py:123)
at openai.api_requestor.APIRequestor.request (/path/to/sdk/requestor.py:85)
at openai.embeddings.Embedding.create (/path/to/sdk/embeddings.py:45)
at main.py:15 Why it happens
This error occurs because the embedding model name provided to the OpenAI embeddings API is incorrect, misspelled, deprecated, or not available in your account's region or subscription. The API cannot find the requested model to generate embeddings.
Detection
Check the API response for a 404 OpenAIError indicating the model name is invalid. Log the model parameter before the API call to verify correctness.
Causes & fixes
Using a non-existent or misspelled embedding model name in the API call
Verify and use a valid embedding model name from the official OpenAI documentation, such as 'text-embedding-3-small' or 'text-embedding-3-large'.
Using a deprecated embedding model that OpenAI no longer supports
Update your code to use a currently supported embedding model listed in the latest OpenAI API docs.
Model access restricted due to account permissions or region limitations
Check your OpenAI account subscription and region availability to ensure you have access to the requested embedding model.
Code: broken vs fixed
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
response = client.embeddings.create(
model='text-embedding-xyz', # invalid model name triggers error
input='Hello world'
)
print(response) import os
from openai import OpenAI
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
response = client.embeddings.create(
model='text-embedding-3-small', # fixed to valid model name
input='Hello world'
)
print(response) # prints embedding vector Workaround
Catch the OpenAIError exception, log the invalid model name, and fallback to a default valid embedding model to continue processing.
Prevention
Always validate embedding model names against the official OpenAI API documentation and keep your dependencies and model names updated to supported versions.