Skip to main content

How to Delete a Stored Response in Microsoft Foundry with the Azure CLI

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

Microsoft Foundry keeps every response of the Responses API, with its input, so a conversation can continue later. Microsoft's guide says how long: By default, response data is retained for 30 days. When a response holds something it shouldn't, such as a password an employee typed, you can delete it sooner with one Azure CLI command.

Syntax​

az rest --method delete --resource "https://ai.azure.com" --url "<project-endpoint>/openai/v1/responses/<response-id>"
PartWhat it is
az restSends a web request signed in as you with your Azure CLI sign-in, so you need no API key.
--method deleteThe kind of request: delete what the URL names.
--resource "https://ai.azure.com"The service your sign-in gets a token for: Microsoft Foundry.
<project-endpoint>Your Foundry project's endpoint, ending in /api/projects/<project-name>.
<response-id>The ID of the response, which starts with resp_.

Foundry answers with "deleted": true and the response's ID. Microsoft's REST reference describes the request: Deletes a response by ID.

The Example​

To show the whole life of a stored response, this example creates one with a harmless question, reads it back, deletes it, and then tries to read it again. A response from your own app works the same way: you only need its ID.

Prerequisites​

  • A Microsoft Foundry project with a model deployment, and a role that lets you use it, such as Foundry User.
  • The Azure CLI, signed in with az login.

Step 1: Write the Request​

Create a file named body.json in the folder your terminal is in:

body.json
{
"model": "gpt-5.6-luna",
"input": "Say hello in one word."
}

model is the name of your model deployment, and input is the question. A file keeps the JSON's quotes intact in every shell.

Step 2: Create a Response​

Send the request, and keep the new response's ID in a variable. Use your own project endpoint in the URL:

Terminal
RESPONSE_ID=$(az rest --method post --resource "https://ai.azure.com" --url "https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp/openai/v1/responses" --body @body.json --query id --output tsv)
echo $RESPONSE_ID
Output
resp_07ff47c598b43ede006b07bd14aa808194b1cb130c89566529
  • --method post creates a response, which Foundry stores.
  • --body @body.json sends the file's content. PowerShell needs the quotes around "@body.json", because @ means something else to it.
  • --query id --output tsv keeps only the response's ID, as plain text, so the variable holds exactly that.

Step 3: Read It Back​

Terminal
az rest --method get --resource "https://ai.azure.com" --url "https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp/openai/v1/responses/$RESPONSE_ID" --query "{id: id, status: status, answer: output[-1].content[0].text}"
Output
{
"answer": "Hello",
"id": "resp_07ff47c598b43ede006b07bd14aa808194b1cb130c89566529",
"status": "completed"
}

The response is stored, and the --query picks out its status and the text of its last output item, the answer.

Step 4: Delete It​

Terminal
az rest --method delete --resource "https://ai.azure.com" --url "https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp/openai/v1/responses/$RESPONSE_ID"
Output
{
"deleted": true,
"id": "resp_07ff47c598b43ede006b07bd14aa808194b1cb130c89566529",
"object": "response"
}

Step 5: Check That It's Gone​

Run the command from Step 3 again:

Output
ERROR: Not Found({"error":{"message":"Response with id 'resp_07ff47c598b43ede006b07bd14aa808194b1cb130c89566529' not found.","type":"invalid_request_error","param":null,"code":null,"request_id":"58e0cad5a28a74d4deaf80497d917e14"}})

Foundry no longer has it. Here is the whole session:

macOS-style terminal window: az rest --method post creates a response and stores its ID in RESPONSE_ID; az rest --method get shows answer Hello and status completed; az rest --method delete returns deleted true and object response; and the same get again fails with ERROR: Not Found, Response with id not found

Common Mistakes​

MistakeWhat happensDo this instead
Leaving out --resource "https://ai.azure.com"The Azure CLI can't tell which service the token is for, sends none, and Foundry refuses the requestAlways pass it with Foundry URLs
Writing --body @body.json in PowerShellPowerShell reads @body as its splatting operator and stops before running anythingQuote it: "@body.json"

Troubleshooting​

SymptomLikely causeFix
ERROR: Not Found … Response with id '…' not found.The response was deleted already, or the ID or project endpoint is wrongCheck the ID and the project endpoint
WARNING: Can't derive appropriate Azure AD resource from --url to acquire an access token, then ERROR: PermissionDenied … Access denied due to invalid subscription key or wrong API endpoint--resource is missingAdd --resource "https://ai.azure.com"
ParserError … The splatting operator '@' cannot be used to reference variables in an expression.@body.json isn't quoted in PowerShellWrite "@body.json"

FAQ​

Which responses should I delete?​

The ones whose input or output holds what you want gone. How to See the Conversation History Microsoft Foundry Stored for a Response shows how to read what a response stored before you decide.

Do I need to delete test responses?​

Foundry deletes them itself after the retention period. Delete one sooner when it holds something that shouldn't stay that long.

Conclusion​

az rest --method delete with your project endpoint and a response ID deletes a stored response, signed in with your Azure CLI sign-in and no API key. Foundry answers "deleted": true, and reading the response afterwards fails with not found.

Additional Resources​