InvalidModelNameError
mistral.client.errors.InvalidModelNameError
Stack trace
mistral.client.errors.InvalidModelNameError: Model 'mistral-unknown-1' not found. Please verify the model name and try again.
File "app.py", line 23, in <module>
response = client.chat.completions.create(model="mistral-unknown-1", messages=messages)
File "mistral/client/chat.py", line 45, in create
raise InvalidModelNameError(f"Model '{model}' not found.") Why it happens
This error occurs when the Mistral SDK is called with a model name that does not exist or is misspelled. The client validates the model name against available models and raises this error if no match is found. It can also happen if the SDK version is outdated and does not recognize newer model names.
Detection
Catch InvalidModelNameError exceptions when calling Mistral client methods and log the model name used to quickly identify invalid or unsupported model names before retrying.
Causes & fixes
Typo or incorrect model name passed to the Mistral client
Verify the exact model name from the official Mistral documentation or SDK and update your code to use the correct model string.
Using a model name not supported by the installed Mistral SDK version
Upgrade the Mistral SDK to the latest version that supports the desired model name.
Missing or incorrect environment variable for Mistral API key causing fallback to invalid defaults
Set the MISTRAL_API_KEY environment variable correctly before running your application.
Code: broken vs fixed
from mistral import Client
client = Client()
messages = [{"role": "user", "content": "Hello"}]
response = client.chat.completions.create(model="mistral-unknown-1", messages=messages) # Invalid model name triggers error
print(response) import os
from mistral import Client
client = Client()
messages = [{"role": "user", "content": "Hello"}]
response = client.chat.completions.create(model="mistral-7b-instruct", messages=messages) # Correct model name
print(response) Workaround
Wrap the call in try/except InvalidModelNameError, then log the invalid model name and fallback to a default known valid model name programmatically.
Prevention
Always verify model names against the official Mistral SDK documentation and keep the SDK updated to support new models; use environment variables for API keys to avoid fallback errors.