Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.37k stars 4.79k forks source link

[BUG] Frequent 401 exceptions when using DefaultAzureCredentials in the AzureOpenAIClient sdk #46398

Closed kushal-r closed 2 weeks ago

kushal-r commented 2 weeks ago

Library name and version

Az Open AI sdk 2.0.0-beta.5

Describe the bug

When using Az Open AI sdk 2.0.0-beta.5 for connecting with text embedding model using default azure credentials, few requests are getting dropped with status 401 Unauthorized. This is not happening for all requests, one in every ~110ms is having this issue.

Expected behavior

These should all result in 200 responses.

Actual behavior

Intermittent 401 responses

Reproduction Steps

Service fabric applications and using dependency injection

 AzureOpenAIClientOptions options = new AzureOpenAIClientOptions();
 _azureOpenAIClient = new(
     new Uri("openai"),
     new DefaultAzureCredential(),
     options);
 _embeddingClient = _azureOpenAIClient.GetEmbeddingClient("modelname");

Invoking the embeddings like this:

var response = await _embeddingClient.GenerateEmbeddingsAsync(texts, options); sdk : Dotnet core: 6.0 Azure.AI.OpenAI Version="2.0.0-beta.5"

System.ClientModel.ClientResultException: Service request failed.
Status: 401 (Unauthorized)

   at Azure.AI.OpenAI.ClientPipelineExtensions.ProcessMessageAsync(ClientPipeline pipeline, PipelineMessage message, RequestOptions options)
   at Azure.AI.OpenAI.Embeddings.AzureEmbeddingClient.GenerateEmbeddingsAsync(BinaryContent content, RequestOptions options)
   at OpenAI.Embeddings.EmbeddingClient.GenerateEmbeddingsAsync(IEnumerable`1 inputs, EmbeddingGenerationOptions options, CancellationToken cancellationToken)
   at 
Services.OpenAITextEmbeddingGenerator.GenerateEmbeddingAsync(IList`1 texts, Int32 dimensions, CancellationToken ct) in D:\a\_work\1\s\src\SV\Services\OpenAITextEmbeddingGenerator.cs:line 73

Environment

Dotnet core 6.0

github-actions[bot] commented 2 weeks ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jpalvarezl @ralph-msft @trrwilson.

mikeharder commented 2 weeks ago

Possible duplicate of #46109

mikeharder commented 2 weeks ago

Closing as duplicate of #46109, unless we have evidence to the contrary.