{"record":{"id":"6b1a1f03cd6732bc","repo":"microsoft/semantic-kernel","slug":"the-anthropic-chat-model-id-is-required","errorCode":null,"errorMessage":"The Anthropic chat model ID is required.","messagePattern":"The Anthropic chat model ID is required\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"critical","filePath":"python/semantic_kernel/connectors/ai/anthropic/services/anthropic_chat_completion.py","lineNumber":113,"sourceCode":"            api_key: The optional API key to use. If provided will override,\n                the env vars or .env file value.\n            async_client: An existing client to use.\n            env_file_path: Use the environment settings file as a fallback\n                to environment variables.\n            env_file_encoding: The encoding of the environment settings file.\n        \"\"\"\n        try:\n            anthropic_settings = AnthropicSettings(\n                api_key=api_key,\n                chat_model_id=ai_model_id,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as ex:\n            raise ServiceInitializationError(\"Failed to create Anthropic settings.\", ex) from ex\n\n        if not anthropic_settings.chat_model_id:\n            raise ServiceInitializationError(\"The Anthropic chat model ID is required.\")\n\n        if not async_client:\n            async_client = AsyncAnthropic(\n                api_key=anthropic_settings.api_key.get_secret_value(),\n            )\n\n        super().__init__(\n            async_client=async_client,\n            service_id=service_id or anthropic_settings.chat_model_id,\n            ai_model_id=anthropic_settings.chat_model_id,\n        )\n\n    # region Overriding base class methods\n\n    # Override from AIServiceClientBase\n    @override\n    def get_prompt_execution_settings_class(self) -> type[\"PromptExecutionSettings\"]:\n        return AnthropicChatPromptExecutionSettings","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/anthropic/services/anthropic_chat_completion.py#L95-L131","documentation":"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.","triggerScenarios":"Constructing AnthropicChatCompletion with ai_model_id=None and no ANTHROPIC_CHAT_MODEL_ID (or equivalent env var) populated.","commonSituations":"Forgot the ai_model_id argument; expected the env var to supply it but it is unset/misnamed; passed an empty string.","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."],"exampleFix":"// before\nsvc = AnthropicChatCompletion(api_key=key)  # no model id -> error\n\n// after\nsvc = AnthropicChatCompletion(ai_model_id=\"claude-3-5-sonnet-latest\", api_key=key)","handlingStrategy":"validation","validationCode":"model = ai_model_id or os.environ.get('ANTHROPIC_CHAT_MODEL_ID')\nif not model:\n    raise ValueError('Anthropic chat model id is required (ai_model_id arg or ANTHROPIC_CHAT_MODEL_ID env)')","typeGuard":"def has_anthropic_model_id(ai_model_id: str | None) -> bool:\n    return bool(ai_model_id or os.environ.get('ANTHROPIC_CHAT_MODEL_ID'))","tryCatchPattern":"try:\n    svc = AnthropicChatCompletion(api_key=key)\nexcept ServiceInitializationError as e:\n    if 'model ID is required' in str(e):\n        svc = AnthropicChatCompletion(ai_model_id='claude-3-5-sonnet-latest', api_key=key)","preventionTips":["Always pass ai_model_id explicitly","Confirm the model-id env var name and value","Log the resolved model id at startup"],"tags":["anthropic","config","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}