Open
Description
Library name and version
Azure.AI.Inference 1.0.0-beta.5
Describe the bug
When creating a ChatCompletionsClient
with an Azure AI Foundry model we are getting the following error:
Azure.RequestFailedException: Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com/ or https://ai.azure.com/), or have expired.
Status: 401 (Unauthorized)
Content:
{ "statusCode": 401, "message": "Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com/ or https://ai.azure.com/), or have expired." }
A mitigation is to add the correct scope manually like so:
var options = new AzureAIInferenceClientOptions();
var credential = new DefaultAzureCredential();
BearerTokenAuthenticationPolicy tokenPolicy = new(credential, ["https://cognitiveservices.azure.com/.default"]);
options.AddPolicy(tokenPolicy, HttpPipelinePosition.PerRetry);
return new ChatCompletionsClient(endpoint, credential, options);
Expected behavior
Works
Actual behavior
Doesn't work
Reproduction Steps
c.f. details
Environment
No response
Metadata
Metadata
Assignees
Labels
This issue is related to a non-management packageWorkflow: This issue is responsible by Azure service team.Issues that are reported by GitHub users external to the Azure organization.Workflow: This issue needs attention from Azure service team or SDK teamThe issue doesn't require a change to the product in order to be resolved. Most issues start as that