openai/openai-python · error · OpenAIError

Configure `provider` on `OpenAI`, not on `AzureOpenAI.with_o

Error message

Configure `provider` on `OpenAI`, not on `AzureOpenAI.with_options()`.

What it means

AzureOpenAI.with_options() rejects the provider option because providers (like bedrock/vertex) are configured on the OpenAI client, not on Azure clients. Azure routing is determined by azure_endpoint/base_url instead.

Source

Thrown at src/openai/lib/azure.py:400

        data_residency: DataResidency | None = None,
        timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
        http_client: httpx2.Client | None = None,
        max_retries: int | NotGiven = NOT_GIVEN,
        default_headers: Mapping[str, str] | None = None,
        set_default_headers: Mapping[str, str] | None = None,
        default_query: Mapping[str, object] | None = None,
        set_default_query: Mapping[str, object] | None = None,
        _enforce_credentials: bool | None = None,
        _extra_kwargs: Mapping[str, Any] = {},
    ) -> Self:
        """
        Create a new client instance re-using the same options given to the current client with optional overriding.
        """
        if data_residency is not None:
            raise OpenAIError("`data_residency` is only supported by OpenAI clients")
        base_url = None if isinstance(base_url, NotGiven) else base_url
        if not isinstance(provider, NotGiven):
            raise OpenAIError("Configure `provider` on `OpenAI`, not on `AzureOpenAI.with_options()`.")
        if is_x509_workload_identity(workload_identity):
            raise OpenAIError("X.509 workload identity is not supported by Azure clients")

        api_key, azure_ad_token, azure_ad_token_provider = _copy_azure_auth(
            api_key,
            azure_ad_token,
            azure_ad_token_provider,
            current_api_key=self._api_key_provider or self.api_key,
            current_token=self._azure_ad_token,
            current_provider=self._azure_ad_token_provider,
        )

        return super().copy(
            api_key=api_key,
            admin_api_key=admin_api_key,
            workload_identity=workload_identity,
            organization=organization,
            project=project,

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Remove provider from the with_options() call for Azure clients
  2. If you need a non-Azure provider, construct OpenAI(provider=...) instead

Example fix

# before
client = azure_client.with_options(provider=Provider.bedrock)
# after
client = openai_client.with_options()
Defensive patterns

Strategy: validation

Validate before calling

opts.pop("provider", None) if isinstance(client, AzureOpenAI) else opts
client.with_options(**opts)

Type guard

from openai import AzureOpenAI
def is_azure_client(c) -> bool: return isinstance(c, AzureOpenAI)

Prevention

When it happens

Trigger: Calling AzureOpenAI(...).with_options(provider=Provider.bedrock) or funneling generic kwargs into with_options on an Azure client.

Common situations: Generic factory code that applies a shared options dict to whichever client it receives; switching from OpenAI(provider=...) to AzureOpenAI without dropping provider.

Related errors


AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28). Data as JSON: /api/errors/bbb59cd97b8d8e18. Report an issue: GitHub.