Issues connecting to Azure AI Foundry models using MS Entra ID from Python

Terrence Rideau 6 Reputation points
2025-05-03T17:28:19.92+00:00

I am trying to connect a non-Azure OpenAI embedding model in AI Foundry using Microsoft Entra ID.

I don't have an issue connecting to Azure OpenAI embedding models using Microsoft Entra ID.

After creating a client and executing the following simple code:

model = EmbeddingsClient(
    endpoint=endpoint,
    credential=DefaultAzureCredential(),
    model=model_name
)

response = model.embed(
    input=["first phrase","second phrase","third phrase"],
)

I get the following error when "response" is created:

Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com or https://ai.azure.com), or have expired.

I have tried using the following in the code but I still have the issue

token_provider = get_bearer_token_provider(
    DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
)
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,396 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.