Skip to content

.NET: [Bug]: Inconsistency in Encrypted Reasoning Support between AIProjectClient and OpenAIClient when using store=false #5633

@CteixeiraPW

Description

@CteixeiraPW

Description

I am observing a discrepancy when attempting to run stateless sessions using the ResponsesClient.

When using the AIProjectClient flow (AIProjectClient -> ProjectOpenAIClient -> ProjectResponsesClient), the client fails when passing back encrypted reasoning messages from previous turns. However, the exact same code and logic work perfectly when using the standard OpenAIClient flow.

Conversely, when using the standard OpenAIClient, the HostedFileSearchTool fails to find the vector store. The tool only functions correctly when using the AIProjectClient flow, but that flow breaks the encrypted reasoning functionality. It appears I have to choose between working reasoning or working file search, but cannot have both in a stateless configuration.

Code Sample

// Configure Foundry Project Options
using System.ClientModel.Primitives;
using Azure.AI.Extensions.OpenAI;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Extensions.AI;
using OpenAI;
using OpenAI.Responses;

Console.Clear();

//Credentials
ChainedTokenCredential credential = new(new VisualStudioCredential(), new InteractiveBrowserCredential());
BearerTokenPolicy tokenPolicy = new(credential, "https://cognitiveservices.azure.com/.default");

//Endpoints
Uri projectEndpoint = new("https://XXXXXXXXXXX.services.ai.azure.com/api/projects/XXXXXXXXXXX");
Uri opentAIEndpoint = new("https://XXXXXXXXXXX.services.ai.azure.com/openai/v1");

// PROJECT CLIENT
var projectClient = new AIProjectClient(projectEndpoint, credential);

// OPENAI CLIENT
var openAIClient = new OpenAIClient(tokenPolicy, new OpenAI.OpenAIClientOptions
{
    Endpoint = opentAIEndpoint,
});


// A chatclient using the ReponseClient stateless, including encrypted reasoning
var chatClient =
    //Encrypted Reasoning does not work with this client - Error: The provided data does not match the expected schema
    //--- Uncomment this line and comment the other client to test
    projectClient.GetProjectOpenAIClient().GetProjectResponsesClient()
    //---
    //But works fine with this one
    //--- 
    //openAIClient.GetResponsesClient()
    //--- 
    .AsIChatClientWithStoredOutputDisabled("gpt-5.4-mini", true)
    .AsBuilder()
    .ConfigureOptions(configure: options =>
    {
        options.Instructions = "You are the official Enterprise AI Assistant for this application. " +
            "Provide polite, professional, and helpful responses directly to the user.\r\n\r\n" +
            "Instructions:\r\n\r\nAnswer the user's inquiry accurately and comprehensively based " +
            "on your foundational knowledge.\r\n\r\nFormat your responses beautifully using Markdown " +
            "where appropriate (e.g., bullet points, bold text, code blocks)";
        options.Reasoning = new ReasoningOptions
        {
            Effort = ReasoningEffort.High,
            Output = ReasoningOutput.Summary
        };
    })
    .Build();


//First turn
List<ChatMessage> chatMessages = [new ChatMessage(ChatRole.User, "Hello, can you help me to calculate the area of my room, and then the area of my house?")];
var response1 = await chatClient.GetResponseAsync(chatMessages);

chatMessages.AddRange(response1.Messages);
PrintResponse(response1);

//Second turn with follow up question
chatMessages.Add(new ChatMessage(ChatRole.User, "The length of the room is 5 meters and the width is 4 meters ad 3 meters high. What is the area?"));
var response2 = await chatClient.GetResponseAsync(chatMessages);

chatMessages.AddRange(response2.Messages);
PrintResponse(response2);

Console.ReadLine();

static void PrintResponse(ChatResponse response)
{
    foreach (var message in response.Messages)
    {
        foreach (var content in message.Contents)
        {
            if (content is TextContent textContent)
            {
                Console.Write("Text Content: " + textContent.Text);
                Console.Write(Environment.NewLine);
                Console.Write(Environment.NewLine);
            }
            else if (content is TextReasoningContent reasoningContent)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("Reasoning Content: " + reasoningContent.Text);
                Console.Write(Environment.NewLine);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("Reasoning Encrypted Content: " + reasoningContent.ProtectedData);
                Console.Write(Environment.NewLine);
                Console.Write(Environment.NewLine);
                Console.ResetColor();
            }
        }
    }
}

Error Messages / Stack Traces

Error Message:
HTTP 400 (ServiceError: invalid_payload)

The provided data does not match the expected schema [Request ID: 4042f7562b21a06ce54c9aeccbf5a5ea]

{
  "code": "invalid_payload",
  "message": "The provided data does not match the expected schema [Request ID: 4042f7562b21a06ce54c9aeccbf5a5ea]",
  "param": "/",
  "type": "invalid_request_error",
  "details": [],
  "additionalInfo": {
    "request_id": "4042f7562b21a06ce54c9aeccbf5a5ea"
  }
}
StackTrace:
   at OpenAI.ClientPipelineExtensions.<ProcessMessageAsync>d__0.MoveNext()
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at OpenAI.Responses.ResponsesClient.<CreateResponseAsync>d__48.MoveNext()
   at Microsoft.Extensions.AI.OpenAIResponsesChatClient.<GetResponseAsync>d__7.MoveNext()
   at Microsoft.Extensions.AI.ConfigureOptionsChatClient.<GetResponseAsync>d__2.MoveNext()
   at Microsoft.Extensions.AI.FunctionInvokingChatClient.<GetResponseAsync>d__41.MoveNext()
   at Microsoft.Extensions.AI.ConfigureOptionsChatClient.<GetResponseAsync>d__2.MoveNext()
   at Program.<<Main>$>d__0.MoveNext() in XXX\Program.cs:line 69

Package Versions

Azure.Identity:1.21.0, Microsoft.Agents.AI.Foundry:1.3.0, Microsoft.Agents.AI.OpenAI:1.3.0

.NET Version

.NET10

Additional Context

Image

Metadata

Metadata

Assignees

Labels

.NETbugSomething isn't working

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions