{"record":{"id":"7e755be78e4ca2eb","repo":"microsoft/autogen","slug":"disallowed-create-args-are-present-disallowed-cr","errorCode":null,"errorMessage":"Disallowed create args are present: {disallowed_create_args.intersection(create_args_keys)}","messagePattern":"Disallowed create args are present: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py","lineNumber":115,"sourceCode":"\nanthropic_init_kwargs = set(inspect.getfullargspec(AsyncAnthropic.__init__).kwonlyargs)\n\n\ndef _anthropic_client_from_config(config: Mapping[str, Any]) -> AsyncAnthropic:\n    # Filter config to only include valid parameters\n    client_config = {k: v for k, v in config.items() if k in anthropic_init_kwargs}\n    return AsyncAnthropic(**client_config)\n\n\ndef _create_args_from_config(config: Mapping[str, Any]) -> Dict[str, Any]:\n    create_args = {k: v for k, v in config.items() if k in anthropic_message_params or k == \"model\"}\n    create_args_keys = set(create_args.keys())\n\n    if not required_create_args.issubset(create_args_keys):\n        raise ValueError(f\"Required create args are missing: {required_create_args - create_args_keys}\")\n\n    if disallowed_create_args.intersection(create_args_keys):\n        raise ValueError(f\"Disallowed create args are present: {disallowed_create_args.intersection(create_args_keys)}\")\n\n    return create_args\n\n\ndef type_to_role(message: LLMMessage) -> str:\n    if isinstance(message, SystemMessage):\n        return \"system\"\n    elif isinstance(message, UserMessage):\n        return \"user\"\n    elif isinstance(message, AssistantMessage):\n        return \"assistant\"\n    else:\n        return \"tool\"\n\n\ndef get_mime_type_from_image(image: Image) -> Literal[\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"]:\n    \"\"\"Get a valid Anthropic media type from an Image object.\"\"\"\n    # Get base64 data first","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py#L97-L133","documentation":"The Anthropic client forbids certain create params (disallowed_create_args — keys the client manages itself, such as 'messages', 'stream', or 'stream_tool_inputs') from being passed in configuration. If any of them appear in the config kwargs, _create_args_from_config raises ValueError listing the offending keys, preventing callers from overriding internal request construction.","triggerScenarios":"Passing messages=..., stream=..., or similar request-body keys as constructor kwargs; forwarding a full request payload dict into AnthropicChatCompletionClient(**payload); copying a raw API request body into client config.","commonSituations":"Treating the client constructor like the messages.create() endpoint; config templating that merges request-body defaults into client kwargs; adapters that pass through user-supplied dicts unfiltered.","solutions":["Remove request-body keys from constructor kwargs; only client options (api_key, base_url, timeout, ...) and model/create params belong there.","Pass messages/stream controls to client.create(...) at call time, not to the constructor.","Whitelist config keys at your config-loading layer instead of forwarding raw dicts."],"exampleFix":"# before\nclient = AnthropicChatCompletionClient(model='claude-sonnet-4-5', api_key=..., stream=True)  # ValueError\n\n# after\nclient = AnthropicChatCompletionClient(model='claude-sonnet-4-5', api_key=...)\nresult = await client.create(messages, stream=True)","handlingStrategy":"validation","validationCode":"ALLOWED = {'model', 'api_key', 'base_url', 'timeout', 'max_tokens', 'temperature', 'top_p', 'model_info'}\n\ndef clean_anthropic_cfg(cfg: dict) -> dict:\n    return {k: v for k, v in cfg.items() if k in ALLOWED}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Whitelist constructor keys instead of forwarding raw dicts","Keep request-body params (messages, stream) at create() call time","Separate 'client config' from 'request template' in your config schema"],"tags":["anthropic","configuration","llm-client","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}