Confirm this is an issue with the Python library and not an underlying OpenAI API
Describe the bug
When the initial token expires during a series of retries due to multiple failures, the azure_ad_token_provider generates a new token as expected. However, this new token is not utilized by AzureOpenAI for the remaining retries.
The problem originates from the openai/lib/azure.py -> _prepare_options function, where the azure_ad_token is only set to headers["Authorization"] during initialization and not when azure_ad_token is changed.
See if headers.get("Authorization") is None below:
def _prepare_options(self, options: FinalRequestOptions) -> None:
headers: dict[str, str | Omit] = {**options.headers} if is_given(options.headers) else {}
options.headers = headers
azure_ad_token = self._get_azure_ad_token()
if azure_ad_token is not None:
if headers.get("Authorization") is None:
headers["Authorization"] = f"Bearer {azure_ad_token}"
To Reproduce
The azure.identity.ClientSecretCredential.get_token function was utilized as the azure_ad_token_provider, and the AzureOpenAI.max_retries was set to 1000. Due to numerous failures and retries, the process exceeded the 60-minute validity period of the token. It is important to note that Langchain is being used, rather than directly interfacing with AzureOpenAI.
Code snippets
No response
OS
SuSE12
Python version
Python 3.9.6
Library version
openai v1.27.0
Confirm this is an issue with the Python library and not an underlying OpenAI API
Describe the bug
When the initial token expires during a series of retries due to multiple failures, the
azure_ad_token_providergenerates a new token as expected. However, this new token is not utilized byAzureOpenAIfor the remaining retries.The problem originates from the
openai/lib/azure.py->_prepare_optionsfunction, where theazure_ad_tokenis only set toheaders["Authorization"]during initialization and not whenazure_ad_tokenis changed.See
if headers.get("Authorization") is Nonebelow:To Reproduce
The
azure.identity.ClientSecretCredential.get_tokenfunction was utilized as theazure_ad_token_provider, and theAzureOpenAI.max_retrieswas set to1000. Due to numerous failures and retries, the process exceeded the 60-minute validity period of the token. It is important to note thatLangchainis being used, rather than directly interfacing withAzureOpenAI.Code snippets
No response
OS
SuSE12
Python version
Python 3.9.6
Library version
openai v1.27.0