microsoft/semantic-kernel · error · ServiceInitializationError
The DeepSeek model ID is required.
Error message
The DeepSeek model ID is required.
What it means
This ServiceInitializationError is raised in the DeepSeek sample when instantiating OpenAISettings reveals no chat model ID. The sample reuses the OpenAI connector (DeepSeek's API is OpenAI-compatible), so it reads the standard OpenAI settings object whose chat_model_id is populated from the OPENAI_CHAT_MODEL_ID environment variable. If that value is absent or empty, the service cannot be constructed and startup aborts.
Source
Thrown at python/samples/concepts/setup/chat_completion_services.py:396
The request settings control the behavior of the service. The default settings are sufficient to get started.
However, you can adjust the settings to suit your needs.
Note: Some of the settings are NOT meant to be set by the user.
Please refer to the Semantic Kernel Python documentation for more information:
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel-python
"""
from openai import AsyncOpenAI
from semantic_kernel.connectors.ai.open_ai import (
OpenAIChatCompletion,
OpenAIChatPromptExecutionSettings,
OpenAISettings,
)
openai_settings = OpenAISettings()
if not openai_settings.api_key:
raise ServiceInitializationError("The DeepSeek API key is required.")
if not openai_settings.chat_model_id:
raise ServiceInitializationError("The DeepSeek model ID is required.")
chat_service = OpenAIChatCompletion(
ai_model_id=openai_settings.chat_model_id,
service_id=service_id,
async_client=AsyncOpenAI(
api_key=openai_settings.api_key.get_secret_value(),
base_url="https://api.deepseek.com",
),
)
request_settings = OpenAIChatPromptExecutionSettings(service_id=service_id)
return chat_service, request_settings
def get_nvidia_chat_completion_service_and_request_settings() -> tuple[
"ChatCompletionClientBase", "PromptExecutionSettings"
]:
"""Return NVIDIA chat completion service and request settings.View on GitHub (pinned to c028a0c7dc)
Solutions
- Set OPENAI_CHAT_MODEL_ID to a DeepSeek model id (deepseek-chat or deepseek-reasoner) in your environment or .env file.
- Verify the .env file lives in the working directory the sample is launched from so OpenAISettings picks it up.
- Print/inspect openai_settings.chat_model_id immediately after construction to confirm the value resolves before the guard fires.
- If setting via code, construct OpenAISettings(chat_model_id='deepseek-chat') explicitly instead of relying on env.
Example fix
// before OPENAI_API_KEY=sk-... # (no model id set) // after OPENAI_API_KEY=sk-... OPENAI_CHAT_MODEL_ID=deepseek-chat
Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
settings = OpenAISettings()
if not settings.chat_model_id:
raise SystemExit("Set OPENAI_CHAT_MODEL_ID (deepseek-chat or deepseek-reasoner) before running.") Prevention
- Keep a checked .env template listing OPENAI_API_KEY and OPENAI_CHAT_MODEL_ID for the DeepSeek sample.
- Validate settings presence in a startup hook before constructing the chat service.
When it happens
Trigger: Calling get_deepseek_chat_completion_service_and_request_settings() when OPENAI_CHAT_MODEL_ID is unset/empty. OpenAISettings() loads at construction time from env vars and/or a .env file; a falsy chat_model_id trips the guard at line 396.
Common situations: The .env file is missing or not on the load path; the variable was named OPENAI_MODEL_ID instead of OPENAI_CHAT_MODEL_ID; the key (OPENAI_API_KEY) was set but the model id was forgotten; running the sample in a fresh shell without exporting the variable.
Related errors
- Failed to initialize the booking sample settings.
- Configuration not found, please setup the notebooks first us
- AZURE_OPENAI_ENDPOINT is not set.
- AZURE_OPENAI_ENDPOINT is not set.
- AZURE_OPENAI_ENDPOINT is not set.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/ed443c88bd0cad96.
Report an issue: GitHub.