Hi @Swamy Nallamalli ,
When you trying default credential you need to add built-in policy to apply correct token scope.
It's mentioned in this github repository kindly check it.
Here, is the code.
var endpoint = new Uri(System.Environment.GetEnvironmentVariable("AZURE_OPENAI_CHAT_ENDPOINT"));
var credential = new DefaultAzureCredential(includeInteractiveCredentials: true);
AzureAIInferenceClientOptions clientOptions = new AzureAIInferenceClientOptions();
BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(credential, new string[] { "https://cognitiveservices.azure.com/.default" });
clientOptions.AddPolicy(tokenPolicy, HttpPipelinePosition.PerRetry);
var client = new ChatCompletionsClient(endpoint, credential, clientOptions);
Here, var credential = new DefaultAzureCredential(includeInteractiveCredentials: true);
you make it true for entra id authentication, false for service principal, environment credential etc.. as per below flow.
- EnvironmentCredential
- WorkloadIdentityCredential
- ManagedIdentityCredential
- SharedTokenCacheCredential
- VisualStudioCredential
- VisualStudioCodeCredential
- AzureCliCredential
- AzurePowerShellCredential
- AzureDeveloperCliCredential
- InteractiveBrowserCredential
Also, if you are using service principal make sure you assign Cognitive Service User and Cognitive Service contributor roles to that service principal in Access Controle(IAM)
Let me know if you have any further queries.
Thank you