microsoft-foundry / microsoft-foundry/foundry-samples

Azure.RequestFailedException: 'The principal `***` lacks the required data action

Open
#155 4 comments 0 reactions 1 assignee View on GitHub

@meerakurup is already working on this.

Since Jul 7, 2025.

Dominant language
Bicep
Stars
445
Forks
494
Avg merge
11h 35m
Merged PRs (30d)
38

Description

I'm trying to use any of C# samples that leverage using PersistentAgentsClient.
I guess, the problem is the configuration, which is not clearly described.

For example, the following code fails:


 PersistentAgentsClient client = AzureAIAgent.CreateAgentsClient("https://***-resource.services.ai.azure.com/api/projects/my-agents-samples", new AzureCliCredential());

 PersistentAgent definition = await client.Administration.CreateAgentAsync(
     "gpt-4o",
     name: "SkAgent01",
     description: "Sample Agent",
     instructions: "Helper");

Getting the following error:

Azure.RequestFailedException: 'The principal *** lacks the required data action Microsoft.CognitiveServices/accounts/AIServices/agents/write to perform POST /api/projects/{projectName}/assistants operation. For instructions on granting the necessary permissions, see https://aka.ms/FoundryPermissions.
Status: 401 (PermissionDenied)

Btw. I have created the project. I'm logged in CLI for sure.

My user is added twice in the user's list: Cognitive Services User and Cognitive Services Contributor.

I have tried using AzureCliCredential and DefaultAzureCredential. Is there some way to use the ApiKey?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.