ValueError
cerebras.client.errors.ValueError: Model name not found or invalid
Stack trace
Traceback (most recent call last):
File "app.py", line 42, in <module>
model = client.load_model(name="invalid_model_name") # triggers error
File "/usr/local/lib/python3.9/site-packages/cerebras/client.py", line 210, in load_model
raise ValueError(f"Model name '{name}' not found or invalid")
ValueError: Model name 'invalid_model_name' not found or invalid Why it happens
The Cerebras SDK requires a valid, registered model name to load a model. If the name provided does not match any available models or is misspelled, the SDK raises this ValueError to indicate the model cannot be found.
Detection
Validate model names against the list of available models from the Cerebras client before calling load_model, or catch ValueError and log the invalid name for debugging.
Causes & fixes
The model name string passed to load_model is misspelled or does not exist in the Cerebras model registry.
Verify the exact model name by listing available models via client.list_models() and use a valid name string.
The model registry is not properly initialized or the client is not connected to the Cerebras backend.
Ensure the Cerebras client is correctly authenticated and connected before loading models, and retry initialization if needed.
Using an outdated or incompatible Cerebras SDK version that does not support the requested model name.
Upgrade the Cerebras SDK to the latest compatible version that includes support for the desired model.
Code: broken vs fixed
from cerebras import CerebrasClient
client = CerebrasClient()
model = client.load_model(name="invalid_model_name") # triggers ValueError
print(model) import os
from cerebras import CerebrasClient
# Use environment variables for credentials
os.environ["CEREBRAS_API_KEY"] = os.getenv("CEREBRAS_API_KEY")
client = CerebrasClient()
# List available models to verify correct name
available_models = client.list_models()
print("Available models:", available_models)
# Use a valid model name from the list
valid_model_name = available_models[0] if available_models else "default_model"
model = client.load_model(name=valid_model_name) # fixed: valid model name
print(model) Workaround
Wrap the load_model call in try/except ValueError, and if caught, fallback to loading a default known model or prompt the user to select a valid model name.
Prevention
Implement validation of model names by fetching and caching the list of available models from the Cerebras client at startup, and enforce selection from this list to prevent invalid names.