{"record":{"id":"6137ca32d01cdb71","repo":"microsoft/autogen","slug":"model-is-required-for-anthropicchatcompletionclien","errorCode":null,"errorMessage":"model is required for AnthropicChatCompletionClient","messagePattern":"model is required for AnthropicChatCompletionClient","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py","lineNumber":367,"sourceCode":"            ToolParam(\n                name=tool_schema[\"name\"],\n                input_schema=tool_params,\n                description=tool_schema.get(\"description\", \"\"),\n            )\n        )\n\n        # Check if the tool has a valid name\n        assert_valid_name(tool_schema[\"name\"])\n\n    return result\n\n\ndef normalize_name(name: str) -> str:\n    \"\"\"\n\n    def __init__(self, **kwargs: Unpack[AnthropicClientConfiguration]):\n        if \"model\" not in kwargs:\n            raise ValueError(\"model is required for AnthropicChatCompletionClient\")\n\n        self._raw_config: Dict[str, Any] = dict(kwargs).copy()\n        copied_args = dict(kwargs).copy()\n\n        model_info: Optional[ModelInfo] = None\n        if \"model_info\" in kwargs:\n            model_info = kwargs[\"model_info\"]\n            del copied_args[\"model_info\"]\n\n        client = _anthropic_client_from_config(copied_args)\n        create_args = _create_args_from_config(copied_args)\n\n        super().__init__(\n            client=client,\n            create_args=create_args,\n            model_info=model_info,\n        )\n","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py#L349-L385","documentation":"AnthropicChatCompletionClient.__init__ hard-requires the 'model' kwarg because every subsequent create call needs it and Anthropic has no default model. The first check in the constructor raises ValueError('model is required for AnthropicChatCompletionClient') when it is absent — before any network or credential work happens.","triggerScenarios":"AnthropicChatCompletionClient(api_key=...) with no model; constructing from a config dict where 'model' is missing or None (None also fails since only presence is checked via 'model' not in kwargs... presence with None passes init but fails later at the API); env-driven configs where ANTHROPIC_MODEL was never set so the key is omitted.","commonSituations":"Porting from OpenAI client where a base-URL default model sometimes works; config loading with .get() returning None or the key dropped by exclude_none; tutorials omitting model in one snippet.","solutions":["Pass model explicitly: AnthropicChatCompletionClient(model='claude-sonnet-4-5', api_key=...).","Fail fast at app startup: assert config.get('model') is truthy before building the client.","When loading from component config, verify the dumped dict retains 'model' (check exclude_none/exclusion behavior)."],"exampleFix":"# before\nclient = AnthropicChatCompletionClient(api_key=os.environ['ANTHROPIC_API_KEY'])  # ValueError\n\n# after\nclient = AnthropicChatCompletionClient(model=os.environ['ANTHROPIC_MODEL'], api_key=os.environ['ANTHROPIC_API_KEY'])","handlingStrategy":"validation","validationCode":"model = os.environ.get('ANTHROPIC_MODEL')\nif not model:\n    raise RuntimeError('ANTHROPIC_MODEL is not set; cannot build Anthropic client')\nclient = AnthropicChatCompletionClient(model=model, api_key=os.environ['ANTHROPIC_API_KEY'])","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check model presence at startup, not lazily at first request","Use exact key 'model' in config files","Watch exclude_none when round-tripping component configs"],"tags":["anthropic","configuration","llm-client","init"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}