{"record":{"id":"a830897637e11cb0","repo":"microsoft/autogen","slug":"required-create-args-are-missing-required-create-a83089","errorCode":null,"errorMessage":"Required create args are missing: {required_create_args - create_args_keys}","messagePattern":"Required create args are missing: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py","lineNumber":141,"sourceCode":"        f\"{AZURE_OPENAI_USER_AGENT} {azure_config[DEFAULT_HEADERS_KEY][USER_AGENT_HEADER_NAME]}\"\n        if USER_AGENT_HEADER_NAME in azure_config[DEFAULT_HEADERS_KEY]\n        else AZURE_OPENAI_USER_AGENT\n    )\n\n    return AsyncAzureOpenAI(**azure_config)\n\n\ndef _openai_client_from_config(config: Mapping[str, Any]) -> AsyncOpenAI:\n    # Shave down the config to just the OpenAI kwargs\n    openai_config = {k: v for k, v in config.items() if k in openai_init_kwargs}\n    return AsyncOpenAI(**openai_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 create_kwargs}\n    create_args_keys = set(create_args.keys())\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    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    return create_args\n\n\n# TODO check types\n# oai_system_message_schema = type2schema(ChatCompletionSystemMessageParam)\n# oai_user_message_schema = type2schema(ChatCompletionUserMessageParam)\n# oai_assistant_message_schema = type2schema(ChatCompletionAssistantMessageParam)\n# oai_tool_message_schema = type2schema(ChatCompletionToolMessageParam)\n\n\ndef type_to_role(message: LLMMessage) -> ChatCompletionRole:\n    if isinstance(message, SystemMessage):\n        return \"system\"\n    elif isinstance(message, UserMessage):\n        return \"user\"\n    elif isinstance(message, AssistantMessage):","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py#L123-L159","documentation":"_create_args_from_config filters an incoming config mapping down to recognized OpenAI completion create-args and asserts that required keys are present. The only required create arg is 'model' (required_create_args = {'model'}); if the config contains no 'model' key, a ValueError listing the missing keys is raised. This runs when a client is constructed from a config mapping/component.","triggerScenarios":"Building a client via config (e.g. OpenAIChatCompletionClient.create_from_config({'api_key': ...}) or component deserialization) where the dict lacks 'model'. Keys that are OpenAI __init__ kwargs (api_key, base_url, timeout) are filtered into the client config and do not count as create args, so config with only those triggers it.","commonSituations":"Config file that sets api_key and organization but omits the model field; component config export/import round-trip that dropped 'model'; passing environment-based config where the model key is conditionally set and the condition is false.","solutions":["Add 'model': '<model-name>' to the config dict before create_from_config / component load","Validate config early: assert 'model' in config before constructing, and surface a clear config error","If the model name lives in an env var, default it: config.setdefault('model', os.environ['OPENAI_MODEL'])"],"exampleFix":"# before\nclient = OpenAIChatCompletionClient.create_from_config({'api_key': key})  # ValueError: Required create args are missing: {'model'}\n\n# after\nclient = OpenAIChatCompletionClient.create_from_config({'model': 'gpt-4o-mini', 'api_key': key})","handlingStrategy":"validation","validationCode":"REQUIRED = {'model'}\nmissing = REQUIRED - set(config.keys())\nif missing:\n    raise ConfigError(f'Config missing {missing}')\nclient = OpenAIChatCompletionClient.create_from_config(config)","typeGuard":null,"tryCatchPattern":"try:\n    client = OpenAIChatCompletionClient.create_from_config(config)\nexcept ValueError as e:\n    if 'Required create args are missing' in str(e):\n        raise ConfigError(f'Add a model to config: {e}') from e\n    raise","preventionTips":["Validate config dicts with pydantic before create_from_config","Default the model from env: config.setdefault('model', os.environ.get('OPENAI_MODEL'))","Add contract tests for config loading paths"],"tags":["openai","config","constructor","validation","autogen"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}