Skip to content

[BUG] Unauthorized exceptions #50872

Open
@sebastienros

Description

@sebastienros

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

No one assigned

    Labels

    AI Model InferenceClientThis issue is related to a non-management packageService AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions