openai/openai-python · error · OpenAIError

Configure `provider` on `AsyncOpenAI`, not on `AsyncAzureOpe

Error message

Configure `provider` on `AsyncOpenAI`, not on `AsyncAzureOpenAI.with_options()`.

What it means

AsyncAzureOpenAI.with_options() rejects the provider option. Providers such as bedrock/vertex are configured on the OpenAI client; Azure routing comes from azure_endpoint instead.

Source

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

        data_residency: DataResidency | None = None,
        timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
        http_client: httpx2.AsyncClient | 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 `AsyncOpenAI`, not on `AsyncAzureOpenAI.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. Drop provider from the Azure with_options() call
  2. Use OpenAI(provider=...) if you actually want another provider

Example fix

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

Strategy: validation

Validate before calling

if "provider" in opts and isinstance(client, AsyncAzureOpenAI):
    opts = {k: v for k, v in opts.items() if k != "provider"}

Type guard

from openai import AsyncAzureOpenAI
def is_async_azure(c) -> bool: return isinstance(c, AsyncAzureOpenAI)

Prevention

When it happens

Trigger: azure_client.with_options(provider=...), or generic kwargs funneled into with_options on an Azure async client.

Common situations: Unified client factories passing a shared options object; switching client classes without pruning options.

Related errors


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