Skip to content
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

Merged
merged 2 commits into from
Aug 20, 2024

Conversation

deyaaeldeen
Copy link
Contributor

  • I understand that this repository is auto-generated and my pull request may not be merged

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

@deyaaeldeen deyaaeldeen requested a review from a team as a code owner August 17, 2024 00:23
@deyaaeldeen deyaaeldeen changed the base branch from master to next August 17, 2024 00:23
@@ -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']) {
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in e557ea4

Copy link
Collaborator

@RobertCraigie RobertCraigie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@stainless-app stainless-app bot merged commit fe8bbaa into openai:next Aug 20, 2024
2 checks passed
stainless-app bot pushed a commit that referenced this pull request Aug 27, 2024
* [Azure] Refresh AAD token on retry

* add context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants