Skip to content

Conversation

kristapratico
Copy link
Owner

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

Changes being requested

Example usages:

from openai import OpenAI, AzureAuth
from azure.identity import get_bearer_token_provider, DefaultAzureCredential

token_provider = get_bearer_token_provider(DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default")

client = OpenAI(
    base_url="https://resource.openai.azure.com/openai/v1",
    auth=AzureAuth(token_provider=token_provider),
    default_query={"api-version": "preview"}
)
from openai import OpenAI, AzureAuth
from azure.identity import DefaultAzureCredential

client = OpenAI(
    base_url="https://resource.openai.azure.com/openai/v1",
    auth=AzureAuth(credential=DefaultAzureCredential()),
    default_query={"api-version": "preview"}
)

Additional context & links

*,
token_provider: AzureTokenProvider | None = None,
credential: TokenCredential | None = None,
scopes: list[str] = ["https://cognitiveservices.azure.com/.default"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick, parameters of type list[str] need to be checked correct type passed in. You will get very unexpected results if you accidentally pass in a str.

token = await self.token_provider()
return token

if self.credential is not None:
Copy link
Collaborator

@johanste johanste Aug 15, 2025

Choose a reason for hiding this comment

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

The AzureAsyncAuth instance needs to cache the bearer token provider.

raise ImportError(
"azure-identity library is not installed. Please install it to use AzureAuth."
) from err
token_provider = get_bearer_token_provider(self.credential, *self.scopes)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to cache this on self.

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