-
Notifications
You must be signed in to change notification settings - Fork 909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Azure] Refresh AAD token on retry #1003
Conversation
@@ -485,7 +485,7 @@ export class AzureOpenAI extends OpenAI { | |||
} | |||
|
|||
protected override async prepareOptions(opts: Core.FinalRequestOptions<unknown>): Promise<void> { | |||
if (opts.headers?.['Authorization'] || opts.headers?.['api-key']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit awkward as users could set the Authorization
header themselves and then we'd override it.
I think a better solution would be to do the same thing as we do in the Python SDK where we create a copy of the options before it's passed to this prepareOptions()
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Azure client doesn't support users setting the authorization header manually. The constructor requires either an API key or a bearer token provider function. If the user really wants to set the authorization header manually, they should provide a bearer token provider function that returns just that value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 mind adding that context as a comment to this code saying why it's okay to unconditionally overwrite the Authorization
header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in e557ea4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
* [Azure] Refresh AAD token on retry * add context
Changes being requested
The AAD token may need to be refreshed between retries so this fix makes sure to always call the token provider irrespective of whether the authorization header is being set.
Additional context & links