BadRequestError
litellm.errors.BadRequestError: model not supported
Stack trace
litellm.errors.BadRequestError: model not supported
File "/app/main.py", line 42, in <module>
response = client.chat.completions.create(model="unsupported-model", messages=messages)
File "/usr/local/lib/python3.9/site-packages/litellm/client.py", line 88, in create
raise BadRequestError("model not supported") Why it happens
This error occurs because the model name passed to LiteLLM's API is either misspelled, deprecated, or not available in the current deployment. The API validates the model parameter and rejects unsupported values with a BadRequestError.
Detection
Check the model parameter before making the API call by validating against the list of supported models from LiteLLM's documentation or via an API endpoint if available.
Causes & fixes
Using a model name that does not exist or is misspelled
Verify the exact model name supported by LiteLLM and correct any typos or casing errors in your code.
Requesting a model that is deprecated or removed from the LiteLLM service
Update your code to use a currently supported model version as listed in the latest LiteLLM documentation.
Passing an empty or null string as the model parameter
Ensure the model parameter is a non-empty string matching a valid model name before calling the API.
Code: broken vs fixed
from litellm import LiteLLM
client = LiteLLM()
messages = [{"role": "user", "content": "Hello"}]
response = client.chat.completions.create(model="unsupported-model", messages=messages) # triggers BadRequestError import os
from litellm import LiteLLM
client = LiteLLM(api_key=os.environ["LITELLM_API_KEY"])
messages = [{"role": "user", "content": "Hello"}]
response = client.chat.completions.create(model="gpt-4o-mini", messages=messages) # fixed with supported model
print(response) Workaround
Catch BadRequestError exceptions and fallback to a default supported model name programmatically to avoid crashes.
Prevention
Always retrieve and cache the list of supported models from LiteLLM's API or documentation and validate model names before making requests.