Azure AI Foundry Code Interpreter: How to delete `assistant-*` `uri_file` datasets created from Files API uploads?

Amol Garse 0 Reputation points
2026-09-11T12:01:58.34+00:00

We are implementing Azure AI Foundry Agents with the Code Interpreter tool, based on the Microsoft documentation:

https://learn.microsoft.com/en-us/azure/foundry/agents/how-to/tools/code-interpreter?pivots=python

Our application uploads a CSV/XLSX file using the Foundry/OpenAI Files API and attaches it to Code Interpreter:

file = openai.files.create(
    purpose="assistants",
    file=csv_file,
)

agent = project.agents.create_version(
    agent_name="MyAgent",
    definition=PromptAgentDefinition(
        model="gpt-5-mini",
        instructions="You are a helpful assistant.",
        tools=[
            CodeInterpreterTool(
                container=AutoCodeInterpreterToolParam(
                    file_ids=[file.id]
                )
            )
        ],
    ),
    description="Code interpreter agent for data analysis and visualization.",
)

The upload receives an ID in the following format:

assistant-H5L...............

After attaching the file to Code Interpreter, Azure AI Foundry displays an entry under:

Build → Data → Datasets

The entry has the following characteristics:

Name: assistant-...
Type: uri_file
Version: 1
Description: <uploaded file name>

A screenshot of the Foundry Datasets page is attached for reference.

Cleanup currently implemented

We can successfully delete the agent version:

project.agents.delete_version(
    agent_name=agent.name,
    agent_version=agent.version,
)

We also delete the original Files API input file:

openai.files.delete(file.id)

We download generated Code Interpreter artifacts, where applicable, before cleanup:

file_content = openai.containers.files.content.retrieve(
    file_id=file_id,
    container_id=container_id,
)

Problem

We cannot find a documented or supported SDK/API operation to delete the Foundry Dataset entry created for an assistant-* file attached to Code Interpreter.

We attempted to investigate deletion through Foundry project routes, but deletion attempts result in 404 Not Found or do not remove the dataset entry. We do not want to depend on portal/browser routes or undocumented APIs for production cleanup.

Additionally, this project does not appear under Azure Machine Learning workspaces in the Azure portal, so Azure ML workspace data-asset deletion does not appear applicable to this managed Foundry project.

Questions for Microsoft

Please provide an official response to the following:

  1. Is the assistant-* uri_file entry shown in Foundry → Build → Data → Datasets expected to be automatically deleted when openai.files.delete(file.id) succeeds?
  2. If yes, what is the expected propagation/retention period before the Dataset entry disappears from the Foundry portal?
  3. If no, what is the supported and documented API/SDK method to delete this specific dataset/resource? Please provide:
  • REST endpoint or Python SDK method;
  • required API version;
  • required permissions/RBAC roles;
  • required deletion order, if relevant;
    • whether the dataset name is the Files API ID (assistant-*) and whether version 1 must be supplied.
  1. Is there currently a retention policy for these Code Interpreter-created uri_file datasets in managed Foundry projects if the application does not explicitly delete them? Specifically:
  • Are they retained indefinitely?
  • Is there a service-managed expiry period?
    • Can a retention policy be configured?
  1. Can an application reliably delete all resources related to a Code Interpreter upload? We need a supported cleanup process for:
  • agent version;
  • input Files API file (assistant-*);
  • Foundry Dataset (uri_file, version 1);
    • Code Interpreter container and generated output artifacts.
    If deletion of the Foundry Dataset is not currently supported programmatically, can Microsoft confirm this explicitly and advise the recommended production cleanup/retention approach?
Foundry Agent Service
Foundry Agent Service

A fully managed platform in Microsoft Foundry for hosting, scaling, and securing AI agents built with any supported framework or model

0 comments No comments

1 answer

Sort by: Most helpful
  1. Allan Solomon Mejia 8,000 Reputation points
    2026-09-11T17:18:42.0233333+00:00

    Hi @Amol Garse

    The cleanup sequence appears to be correct for the resources currently available via the documented Foundry Agent Service APIs.

    Microsoft treats files uploaded to the Foundry Agent Service as persistent data and keeps them that way until you deliberately delete them. The specified procedure for cleaning up uploaded files is to delete the underlying file object, which removes the file from the Code Interpreter and its associated file-search configurations.

    So this part of your cleanup is correct:

    project.agents.delete_version(
        agent_name=agent.name,
        agent_version=agent.version,
    )
    openai.files.delete(file.id)
    

    The Code Interpreter documentation states the same: applications should remove the agent version, the conversation, and the uploaded files when they are no longer needed. It doesn't include a separate operation to delete a Dataset for the assistant-* uri_file object that appears under Build > Data > Datasets.

    Do not make use of the Azure Machine Learning data-asset APIs in relation to that portal entry unless Microsoft itself confirms that this managed Foundry Dataset is an AML data asset. The current Foundry documentation does not show equivalence between the two.

    There is an important distinction between two objects here:

    1. The Files API object

    This is the assistant-* file returned by openai.files.create(). Microsoft provides a supported delete operation for this object.

    1. The uri_file Dataset representation shown by the Foundry portal

    I cannot find a currently documented Foundry Agent Service REST or Python SDK operation that independently deletes this portal Dataset representation after the underlying Files API object has been deleted.

    I have not been able to locate a currently documented Foundry Agent Service REST or Python SDK operation which, on its own, deletes this portal Dataset representation after the underlying Files API object has been deleted.

    I therefore do not advise using the portal's private/browser endpoints or the undocumented project routes in a production environment, since a 404 response from those routes does not prove that the Files API cleanup has failed.

    A good way to verify this would be to invoke the Files API that has been documented after the file has been deleted and then check that the assistant-* file can no longer be retrieved; if the deletion has succeeded on the Files API but the entry in the Dataset still appears, this strongly indicates that you are dealing with either a portal/catalog representation which has delayed cleanup or with an internally managed resource that is separate from the Files API object.

    Regarding data retention, Microsoft's current FAQ for Agent Service states that agent data such as files and vector stores continues to be retained unless it is explicitly deleted. However, I haven't found documentation outlining a separate retention or expiration period for the uri_file Dataset entries generated by the Code Interpreter, or a configurable retention policy for these entries.

    You can't use the seven-day vector-store expiration that has been documented in this instance, since that behavior relates to conversation vector stores and is not applicable to Code Interpreter uri_file Dataset entries.

    So for your four questions, based on the currently published API surface:

    1. Files API cleanup: openai.files.delete(file.id) is the documented operation and should be part of production cleanup.
    2. Separate Dataset deletion API: I can't find a documented/supported Agent Service API or SDK operation for independently deleting the assistant-* uri_file Dataset representation shown in the portal.
    3. Dataset propagation/retention period: I can't find a documented SLA or expiry period for that portal entry after deleting the Files API.
    4. Code Interpreter container: Code Interpreter runs in a Microsoft-managed isolated sandbox with a limited session lifetime; sessions are active for up to one hour. Generated artifacts that need to persist should therefore be downloaded before cleanup/session expiration, as you're already doing.

    Since your requirement is specifically for production-grade deterministic deletion, I believe the other questions should be confirmed by the engineering team at the Foundry Agent Service: whether that Dataset entry is just an internal or catalog representation of the Files object which has been deleted, whether it undergoes an asynchronous garbage-collection period, or whether there is another deletion API that is not currently documented.

    The most useful test case in this situation would be for a Microsoft moderator to escalate the issue: the Files API should return a success message when a file is deleted, the following retrieval should show that the file does not exist, but the Build > Data > Datasets section should still display assistant-<id>, of type uri_file, version 1, thus clearly identifying the discrepancy in the lifecycle.

    References:

    Use Code Interpreter with Microsoft Foundry agents

    Foundry Agent Service FAQ - data storage and deletion

    File search - file deletion behavior

    Vector stores - lifecycle and expiration policies

    =============================================================================

    Help make this community better for everyone: If this answer helped or resolved your issue, please accept it or upvote it. If not, share more details in a comment so we can continue the discussion and find the right solution.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.