microsoft/semantic-kernel · error · ServiceInitializationError
Failed to create NVIDIA settings.
Error message
Failed to create NVIDIA settings.
What it means
Raised as ServiceInitializationError when constructing the pydantic `NvidiaSettings` for the NVIDIA chat completion service raises a `ValidationError`. The original validation error is passed as a second arg and chained with `from ex`. This is a configuration/structure failure, not a network failure.
Source
Thrown at python/semantic_kernel/connectors/ai/nvidia/services/nvidia_chat_completion.py:96
the env vars or .env file value.
base_url (str | None): Custom API endpoint. (Optional)
client (Optional[AsyncOpenAI]): An existing client to use. (Optional)
env_file_path (str | None): Use the environment settings file as a fallback
to environment variables. (Optional)
env_file_encoding (str | None): The encoding of the environment settings file. (Optional)
instruction_role (Literal["system", "user", "assistant", "developer"] | None): The role to use for
'instruction' messages. Defaults to "system". (Optional)
"""
try:
nvidia_settings = NvidiaSettings(
api_key=api_key,
base_url=base_url,
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 NVIDIA settings.", ex) from ex
if not client and not nvidia_settings.api_key:
raise ServiceInitializationError("The NVIDIA API key is required.")
if not nvidia_settings.chat_model_id:
# Default fallback model
nvidia_settings.chat_model_id = DEFAULT_NVIDIA_CHAT_MODEL
logger.warning(f"Default chat model set as: {nvidia_settings.chat_model_id}")
# Create client if not provided
if not client:
client = AsyncOpenAI(
api_key=nvidia_settings.api_key.get_secret_value() if nvidia_settings.api_key else None,
base_url=nvidia_settings.base_url,
)
super().__init__(
ai_model_id=nvidia_settings.chat_model_id,
api_key=nvidia_settings.api_key.get_secret_value() if nvidia_settings.api_key else None,View on GitHub (pinned to c028a0c7dc)
Solutions
- Inspect the chained `ex` for the exact failing field.
- Pass valid base_url (full https:// URL) and api_key explicitly, or fix the matching env vars.
- Verify env_file_path exists and is parseable in the given encoding.
- Confirm NVIDIA settings field names against the NvidiaSettings model (NVIDIA_API_KEY, NVIDIA_BASE_URL, NVIDIA_CHAT_MODEL_ID).
Example fix
# before
svc = NvidiaChatCompletion() # -> ServiceInitializationError
# after
svc = NvidiaChatCompletion(
api_key=os.environ['NVIDIA_API_KEY'],
base_url='https://integrate.api.nvidia.com/v1',
ai_model_id='meta/llama3-8b-instruct',
) Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel.connectors.ai.nvidia import NvidiaSettings
from pydantic import ValidationError
try:
NvidiaSettings(api_key=os.environ.get('NVIDIA_API_KEY'),
base_url=os.environ.get('NVIDIA_BASE_URL', 'https://integrate.api.nvidia.com/v1'),
chat_model_id='meta/llama3-8b-instruct')
except ValidationError as e:
raise SystemExit(f'Fix NVIDIA settings first: {e}') Type guard
from semantic_kernel.exceptions import ServiceInitializationError
def is_nvidia_settings_error(e: BaseException) -> bool:
return isinstance(e, ServiceInitializationError) and 'Failed to create NVIDIA settings' in str(e) Try / catch
from semantic_kernel.exceptions import ServiceInitializationError
try:
svc = NvidiaChatCompletion()
except ServiceInitializationError as e:
raise SystemExit(f'NVIDIA chat misconfigured: {e.__cause__ or e}') from e Prevention
- Always pass base_url as a full https:// URL.
- Validate NvidiaSettings with pydantic before constructing the service.
- Ensure env_file_path exists when used.
When it happens
Trigger: Constructing `NvidiaChatCompletion(...)` where merged config (constructor args + NVIDIA_API_KEY/NVIDIA_BASE_URL/NVIDIA_CHAT_MODEL_ID env + .env) fails pydantic validation: invalid base_url format (not a valid HttpUrl), api_key wrong type, or env_file unreadable.
Common situations: NVIDIA_BASE_URL missing the scheme (e.g. 'host.com' instead of 'https://host.com'), a .env path that does not exist, NVIDIA_API_KEY empty string failing the SecretStr validator, pydantic v1/v2 behavior differences.
Related errors
- Failed to create NVIDIA settings.
- Failed to create Ollama settings.
- Failed to validate Mistral AI settings: {e}
- The NVIDIA API key is required.
- Failed to create Ollama settings.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/2c468e45cec6f466.
Report an issue: GitHub.