microsoft/semantic-kernel · critical · ServiceInitializationError
The Anthropic chat model ID is required.
Error message
The Anthropic chat model ID is required.
What it means
After settings are created successfully, the constructor checks that chat_model_id is truthy; if it is empty/None it raises ServiceInitializationError. This is a distinct, later check than the settings ValidationError and points specifically at the model id.
Source
Thrown at python/semantic_kernel/connectors/ai/anthropic/services/anthropic_chat_completion.py:113
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:
anthropic_settings = AnthropicSettings(
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 Anthropic settings.", ex) from ex
if not anthropic_settings.chat_model_id:
raise ServiceInitializationError("The Anthropic chat model ID is required.")
if not async_client:
async_client = AsyncAnthropic(
api_key=anthropic_settings.api_key.get_secret_value(),
)
super().__init__(
async_client=async_client,
service_id=service_id or anthropic_settings.chat_model_id,
ai_model_id=anthropic_settings.chat_model_id,
)
# region Overriding base class methods
# Override from AIServiceClientBase
@override
def get_prompt_execution_settings_class(self) -> type["PromptExecutionSettings"]:
return AnthropicChatPromptExecutionSettingsView on GitHub (pinned to c028a0c7dc)
Solutions
- Pass ai_model_id explicitly (e.g. "claude-3-5-sonnet-latest").
- Set the model id environment variable AnthropicSettings reads, and confirm it is loaded.
- Log the resolved chat_model_id during startup to catch empty values early.
Example fix
// before svc = AnthropicChatCompletion(api_key=key) # no model id -> error // after svc = AnthropicChatCompletion(ai_model_id="claude-3-5-sonnet-latest", api_key=key)
Defensive patterns
Strategy: validation
Validate before calling
model = ai_model_id or os.environ.get('ANTHROPIC_CHAT_MODEL_ID')
if not model:
raise ValueError('Anthropic chat model id is required (ai_model_id arg or ANTHROPIC_CHAT_MODEL_ID env)') Type guard
def has_anthropic_model_id(ai_model_id: str | None) -> bool:
return bool(ai_model_id or os.environ.get('ANTHROPIC_CHAT_MODEL_ID')) Try / catch
try:
svc = AnthropicChatCompletion(api_key=key)
except ServiceInitializationError as e:
if 'model ID is required' in str(e):
svc = AnthropicChatCompletion(ai_model_id='claude-3-5-sonnet-latest', api_key=key) Prevention
- Always pass ai_model_id explicitly
- Confirm the model-id env var name and value
- Log the resolved model id at startup
When it happens
Trigger: Constructing AnthropicChatCompletion with ai_model_id=None and no ANTHROPIC_CHAT_MODEL_ID (or equivalent env var) populated.
Common situations: Forgot the ai_model_id argument; expected the env var to supply it but it is unset/misnamed; passed an empty string.
Related errors
- Failed to create Anthropic settings.
- Failed to create Azure OpenAI settings: {exc}
- Please provide an Azure OpenAI endpoint
- Please provide an Azure OpenAI deployment name
- Tool choice 'none' is not supported by Anthropic.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/6b1a1f03cd6732bc.
Report an issue: GitHub.