ValueError
litellm.errors.ValueError: Function calling not supported for this model
Stack trace
Traceback (most recent call last):
File "app.py", line 42, in <module>
response = client.chat.completions.create(
File "/usr/local/lib/python3.9/site-packages/litellm/client.py", line 120, in create
raise ValueError("Function calling not supported for this model")
ValueError: Function calling not supported for this model Why it happens
LiteLLM only supports function calling with specific models that have this capability enabled. When you try to use function calling with a model that lacks this support, the client raises a ValueError to prevent unsupported API calls.
Detection
Check the model name or capabilities before enabling function calling. Catch ValueError exceptions from the client to log unsupported model usage.
Causes & fixes
Using a LiteLLM model that does not support function calling (e.g., base or older models).
Switch to a LiteLLM model version that explicitly supports function calling, such as 'litellm-4o' or newer models documented to support this feature.
Passing function calling parameters to the client when the selected model does not have function calling enabled.
Remove function calling parameters from the request or conditionally add them only if the model supports function calling.
Code: broken vs fixed
import os
from litellm import LiteLLM
client = LiteLLM(api_key=os.environ['LITELLM_API_KEY'])
response = client.chat.completions.create(
model="litellm-base",
messages=[{"role": "user", "content": "Call a function"}],
functions=[{"name": "get_time", "parameters": {}}], # This triggers the error
)
print(response) import os
from litellm import LiteLLM
client = LiteLLM(api_key=os.environ['LITELLM_API_KEY'])
response = client.chat.completions.create(
model="litellm-4o", # Changed to a model that supports function calling
messages=[{"role": "user", "content": "Call a function"}],
functions=[{"name": "get_time", "parameters": {}}], # Function calling now supported
)
print(response) # Should print the function call response without error Workaround
Wrap the call in try/except ValueError, and if caught, retry the request without function calling parameters or switch to a supported model dynamically.
Prevention
Check the LiteLLM model documentation for function calling support before enabling it in your requests, and implement model capability checks in your code.