diff --git a/python/semantic_kernel/connectors/ai/open_ai/services/azure_chat_completion.py b/python/semantic_kernel/connectors/ai/open_ai/services/azure_chat_completion.py index 92dc436c9f86..e9a419247649 100644 --- a/python/semantic_kernel/connectors/ai/open_ai/services/azure_chat_completion.py +++ b/python/semantic_kernel/connectors/ai/open_ai/services/azure_chat_completion.py @@ -94,15 +94,23 @@ def __init__( if not azure_openai_settings.chat_deployment_name: raise ServiceInitializationError("chat_deployment_name is required.") - # If the api_key is none, and the ad_token is none, and the ad_token_provider is none, + # If the async_client is None, the api_key is none, the ad_token is none, and the ad_token_provider is none, # then we will attempt to get the ad_token using the default endpoint specified in the Azure OpenAI settings. - if api_key is None and ad_token_provider is None and azure_openai_settings.token_endpoint and ad_token is None: + if ( + async_client is None + and azure_openai_settings.api_key is None + and ad_token_provider is None + and ad_token is None + and azure_openai_settings.token_endpoint + ): ad_token = azure_openai_settings.get_azure_openai_auth_token( token_endpoint=azure_openai_settings.token_endpoint ) - if not azure_openai_settings.api_key and not ad_token and not ad_token_provider: - raise ServiceInitializationError("Please provide either api_key, ad_token or ad_token_provider") + if not async_client and not azure_openai_settings.api_key and not ad_token and not ad_token_provider: + raise ServiceInitializationError( + "Please provide either a custom client, or an api_key, an ad_token or an ad_token_provider" + ) super().__init__( deployment_name=azure_openai_settings.chat_deployment_name,