{"record":{"id":"9739da7a59a4d620","repo":"openai/openai-python","slug":"provider-cannot-be-combined-with-top-level-form","errorCode":null,"errorMessage":"`provider` cannot be combined with top-level {formatted}. Move provider authentication and routing options into `{provider_name}(...)`.","messagePattern":"`provider` cannot be combined with top-level (.+?)\\. Move provider authentication and routing options into `(.+?)\\(\\.\\.\\.\\)`\\.","errorType":"exception","errorClass":"OpenAIError","httpStatus":null,"severity":"error","filePath":"src/openai/_client.py","lineNumber":221,"sourceCode":"            data_residency, base_url, provider=provider, websocket_base_url=websocket_base_url\n        )\n        base_url = x509_data_residency_base_url(base_url, data_residency, workload_identity)\n        provider_runtime: _ProviderRuntime | None = None\n        if provider is not None:\n            provider_name = _provider_name(provider)\n            conflicts = [\n                name\n                for name, value in (\n                    (\"api_key\", api_key),\n                    (\"admin_api_key\", admin_api_key),\n                    (\"workload_identity\", workload_identity),\n                    (\"base_url\", base_url),\n                )\n                if value is not None\n            ]\n            if conflicts:\n                formatted = \", \".join(f\"`{name}`\" for name in conflicts)\n                raise OpenAIError(\n                    f\"`provider` cannot be combined with top-level {formatted}. \"\n                    f\"Move provider authentication and routing options into `{provider_name}(...)`.\"\n                )\n\n            provider_runtime = _configure_provider(provider)\n\n        self._provider = provider\n        self._provider_runtime = provider_runtime\n\n        if api_key is not None and api_key != WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER and workload_identity is not None:\n            raise OpenAIError(\"The `api_key` and `workload_identity` arguments are mutually exclusive\")\n\n        if is_x509_workload_identity(workload_identity):\n            workload_identity = workload_identity.copy()\n        self.workload_identity = workload_identity if provider_runtime is None else None\n\n        if provider_runtime is not None:\n            self.api_key = \"\"","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_client.py#L203-L239","documentation":"The sync `OpenAI(...)` constructor rejects mixing the `provider` parameter with top-level routing/auth options (`api_key`, `base_url`, `workload_identity`, etc.). Provider configuration must be self-contained via `OpenAIProvider(...)` (or the provider object) so credentials and endpoints come from one place.","triggerScenarios":"`OpenAI(provider=..., api_key=...)`, `OpenAI(provider=..., base_url=...)`, or passing `workload_identity`/`admin_api_key` alongside `provider`; env vars are fine but explicit kwargs conflict.","commonSituations":"Adopting the provider API while keeping legacy kwargs; copy-pasting older constructor snippets onto new provider-based code.","solutions":["Move auth/routing kwargs into the provider object, e.g. `OpenAI(provider=OpenAIProvider(api_key=..., base_url=...))`","Or drop `provider` and keep top-level kwargs","Check the conflict list in the message for exactly which kwargs to migrate"],"exampleFix":"# before\nclient = OpenAI(provider=provider, api_key='sk-...', base_url='https://x')\n\n# after\nclient = OpenAI(provider=OpenAIProvider(api_key='sk-...', base_url='https://x'))","handlingStrategy":"validation","validationCode":"provider_kwargs = {'api_key': k, 'base_url': u}\nif provider is not None and any(v is not None for v in provider_kwargs.values()):\n    provider = provider.replace_with(**provider_kwargs)  # or build provider with these\n    provider_kwargs = {}","typeGuard":null,"tryCatchPattern":"try:\n    client = OpenAI(provider=provider, **kwargs)\nexcept OpenAIError as e:\n    if 'cannot be combined with top-level' in str(e):\n        # move kwargs into the provider and retry\n        client = OpenAI(provider=provider_with(kwargs))\n    else:\n        raise","preventionTips":["Adopt one style: all auth/routing via provider, or all via top-level kwargs","Parse the message's conflict list programmatically in config layers"],"tags":["provider","constructor","configuration","conflict"],"backgroundTag":"conflicting-constructor-arguments","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}