microsoft/semantic-kernel · error · ServiceInitializationError
Failed to create MistralAI settings.
Error message
Failed to create MistralAI settings.
What it means
Raised by MistralAIChatCompletion.__init__ when constructing MistralAISettings raises a pydantic ValidationError. The constructor wraps the validation failure (api_key, chat_model_id, env) into a ServiceInitializationError chained from the cause, failing fast at service creation.
Source
Thrown at python/semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_chat_completion.py:94
ai_model_id : MistralAI model name, see
https://docs.mistral.ai/getting-started/models/
service_id : Service ID tied to the execution settings.
api_key : The optional API key to use. If provided will override,
the env vars or .env file value.
async_client : An existing client to use.
env_file_path : Use the environment settings file as a fallback
to environment variables.
env_file_encoding : The encoding of the environment settings file.
"""
try:
mistralai_settings = MistralAISettings(
api_key=api_key,
chat_model_id=ai_model_id,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
except ValidationError as ex:
raise ServiceInitializationError("Failed to create MistralAI settings.", ex) from ex
if not mistralai_settings.chat_model_id:
raise ServiceInitializationError("The MistralAI chat model ID is required.")
if not async_client:
async_client = Mistral(
api_key=mistralai_settings.api_key.get_secret_value(),
)
super().__init__(
async_client=async_client,
service_id=service_id or mistralai_settings.chat_model_id,
ai_model_id=ai_model_id or mistralai_settings.chat_model_id,
)
# region Overriding base class methods
# Override from AIServiceClientBaseView on GitHub (pinned to c028a0c7dc)
Solutions
- Inspect the chained cause (ValidationError detail) to find the failing field.
- Set MISTRAL_API_KEY (and model id) via env / .env, or pass api_key and ai_model_id explicitly.
- Verify env_file_path is correct and readable.
Example fix
# before svc = MistralAIChatCompletion() # after svc = MistralAIChatCompletion(ai_model_id='mistral-large-latest', api_key=os.environ['MISTRAL_API_KEY'])
Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel.connectors.ai.mistral_ai.mistral_ai_settings import MistralAISettings
try:
s = MistralAISettings(api_key=..., chat_model_id=...)
except Exception as e:
print('config invalid:', e) Try / catch
try:
svc = MistralAIChatCompletion(api_key=..., ai_model_id=...)
except ServiceInitializationError as e:
raise Prevention
- Set MISTRAL_API_KEY and a model id via env / .env or pass explicitly.
- Validate MistralAISettings construction in isolation.
- Confirm env_file_path correctness.
When it happens
Trigger: Instantiating MistralAIChatCompletion with missing/malformed api_key or model id and no env fallback. A .env file that doesn't satisfy MistralAISettings validators.
Common situations: MISTRAL_API_KEY not set. Wrong env file path/encoding. Empty/malformed api_key or model id passed explicitly.
Related errors
- Failed to validate Vertex AI settings: {e}
- Failed to validate Vertex AI settings: {e}
- Failed to validate Vertex AI settings: {e}
- The MistralAI chat model ID is required.
- Failed to validate Mistral AI settings: {e}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/9c72ff8973336364.
Report an issue: GitHub.