How to access file generated by code interpreter

Jeremy Borg 0 Reputation points
2025-10-14T13:03:01.8366667+00:00

I have created an Agent in Azure AI Foundry using GPT-4o and configured with code interpreter. I want to be able to export tabular data generated by the code interpreter as a CSV file and download it outside of the AI Foundry Playground.

When I ask the agent to generate a graph, it returns a file_id in the code interpreter output, which I then use to download the image by calling the save_file function. However when the code interpreter generates csv files, it does not return a file_id.

How can I download the tabular data (csv, excel etc) generated by the code interpreter

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 25,761 Reputation points Volunteer Moderator
    2025-10-22T09:44:09.6566667+00:00

    Hello Jeremy Borg,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you would like to access file generated by code interpreter.

    Follow these four steps for AI Hub Projects, not AI Foundry. https://free.blessedness.top/en-us/azure/ai-foundry/openai/how-to/code-interpreter

    A. Modify your Python code to explicitly save the CSV file and return it as a downloadable object. For an example:

            import pandas as pd
            df = pd.DataFrame(data)
            df.to_csv("output.csv", index=False)
          return "output.csv"
    

    This is to make sure the agent is configured to return file references.

    B. Use FileReferenceContent or StreamingFileReferenceContent in AI Hub, files are returned as part of the assistant's response. So, use the SDK to extract file references:

       foreach (var chunk in agent.InvokeStreamingAsync(message, thread))
            {
                var fileIds = chunk.Items.OfType<StreamingFileReferenceContent>().Select(f => f.FileId);
                foreach (var id in fileIds)
                {
                    var file = fileClient.GetFile(id);
                    var data = await fileClient.DownloadFileAsync(id);
                    File.WriteAllBytes($"downloads/{file.Filename}", data.ToArray());
                }
            }
    

    For a similar accepted answer on this platform, see - https://free.blessedness.top/en-us/answers/questions/2288698/how-to-download-files-generated-by-the-code-interp

    C. Make sure you're using the correct SDK for AI Hub (not AI Foundry). - https://free.blessedness.top/en-us/azure/ai-foundry/agents/how-to/tools/code-interpreter

    D. If SDK fails, manually export CSV from the AI Foundry Playground (if available).

    I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is 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.