microsoft/autogen · error · ValueError
model is required for AnthropicChatCompletionClient
Error message
model is required for AnthropicChatCompletionClient
What it means
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.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py:367
ToolParam(
name=tool_schema["name"],
input_schema=tool_params,
description=tool_schema.get("description", ""),
)
)
# Check if the tool has a valid name
assert_valid_name(tool_schema["name"])
return result
def normalize_name(name: str) -> str:
"""
def __init__(self, **kwargs: Unpack[AnthropicClientConfiguration]):
if "model" not in kwargs:
raise ValueError("model is required for AnthropicChatCompletionClient")
self._raw_config: Dict[str, Any] = dict(kwargs).copy()
copied_args = dict(kwargs).copy()
model_info: Optional[ModelInfo] = None
if "model_info" in kwargs:
model_info = kwargs["model_info"]
del copied_args["model_info"]
client = _anthropic_client_from_config(copied_args)
create_args = _create_args_from_config(copied_args)
super().__init__(
client=client,
create_args=create_args,
model_info=model_info,
)
View on GitHub (pinned to 027ecf0a37)
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).
Example fix
# before client = AnthropicChatCompletionClient(api_key=os.environ['ANTHROPIC_API_KEY']) # ValueError # after client = AnthropicChatCompletionClient(model=os.environ['ANTHROPIC_MODEL'], api_key=os.environ['ANTHROPIC_API_KEY'])
Defensive patterns
Strategy: validation
Validate before calling
model = os.environ.get('ANTHROPIC_MODEL')
if not model:
raise RuntimeError('ANTHROPIC_MODEL is not set; cannot build Anthropic client')
client = AnthropicChatCompletionClient(model=model, api_key=os.environ['ANTHROPIC_API_KEY']) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Required create args are missing: {required_create_args - cr
- Disallowed create args are present: {disallowed_create_args.
- config is required when using local Mem0 client (is_cloud=Fa
- tool_choice must be a Tool object, 'auto', 'required', or 'n
- Unknown content type: {part}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/6137ca32d01cdb71.
Report an issue: GitHub.