ValueError
litellm.config.ValueError: Model alias not found in config
Stack trace
Traceback (most recent call last):
File "app.py", line 12, in <module>
client = LiteLLMClient(model_alias="my-model") # triggers error
File "/usr/local/lib/python3.9/site-packages/litellm/client.py", line 45, in __init__
self.model_config = config.get_model_config(model_alias)
File "/usr/local/lib/python3.9/site-packages/litellm/config.py", line 30, in get_model_config
raise ValueError(f"Model alias '{model_alias}' not found in config")
ValueError: Model alias 'my-model' not found in config Why it happens
LiteLLM requires a model alias to be defined in its configuration to map to a valid model specification. If the alias provided to the client or loader is not present in the config file or dictionary, LiteLLM cannot resolve which model to load, causing this error.
Detection
Check for ValueError exceptions during LiteLLM client initialization and log the model alias being requested to verify it exists in the config before proceeding.
Causes & fixes
The model alias passed to LiteLLM client is not defined in the LiteLLM config file or dictionary.
Add the missing model alias with its corresponding model details to the LiteLLM configuration before initializing the client.
Typo or mismatch in the model alias string used in code versus the config keys.
Verify and correct the model alias string in your code to exactly match the key defined in the LiteLLM config, including case sensitivity.
The LiteLLM config file is not loaded or is empty due to a path or environment variable misconfiguration.
Ensure the config file path or environment variable is correctly set and the config loads successfully before creating the LiteLLM client.
Code: broken vs fixed
from litellm import LiteLLMClient
client = LiteLLMClient(model_alias="my-model") # triggers ValueError: Model alias not found in config
response = client.chat("Hello")
print(response) import os
from litellm import LiteLLMClient
# Set environment variable or ensure config includes 'my-model'
os.environ["LITELLM_CONFIG_PATH"] = "/path/to/litellm_config.yaml"
client = LiteLLMClient(model_alias="my-model") # fixed: model alias exists in config
response = client.chat("Hello")
print(response) # prints model response Workaround
Catch the ValueError when initializing LiteLLMClient, then fallback to a default model alias known to exist in the config or prompt the user to update the config.
Prevention
Always validate that all model aliases used in code are present and correctly spelled in the LiteLLM configuration before deployment, and automate config validation in CI pipelines.