How to access files generated by AI Assistants (Assistants API)?

GenixPRO 206 Reputation points
2025-05-23T05:14:00.14+00:00

Hi.

  1. Our mobile app deploys assistants (create once in AI Foundry, then use assistant_id to create thread for each user @ runtime) to generate a variety of plans (PDFs) or images.
  2. These files are being generated and saved in Data files sandbox: /mnt/data/<filename>
  3. How do we retrieve these files from Data files using File ID? How do we access Data files location? When user requests access path or link to generated file, assistant replies with a sandbox location. However that's not a fully qualified URL that user can access publicly.
  4. Solution: We may retrieve the file based on File ID and purpose = "assistant_output" -> save to a public URL and share the URL back with user to access. Would that be considered a better approach to render any type of file display?
  5. Is there an easier way to access file directly from Data files (storage) and render in-app?

Appreciate help.

Thanks.

Foundry Tools
Foundry Tools

Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform

Locked Question. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2025-05-26T05:24:42.62+00:00

    Hi @GenixPRO

    I understand that you are encountering an issue with accessing the files via the assistant API. Here are some potential solutions. To retrieve files saved in your Data files sandbox, you can utilize the files. Content endpoint.

    
    from openai import AzureOpenAI
    
    client = AzureOpenAI(
        api_key=os.getenv("AZURE_OPENAI_API_KEY"),
        api_version="2024-05-01-preview",
        azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT")
    )
    
    # Replace 'your_file_id' with your actual File ID
    file_data = client.files.content("your_file_id")
    with open("downloaded_file.pdf", "wb") as file:
        file.write(file_data.read())
    
    
    

     After retrieving the file, saving it to a public URL is a recommended method for sharing. You can use services such as Azure Blob Storage to host your files publicly and obtain the URL. Currently, accessing files directly from the Data files location with a fully qualified public URL is not straightforward, as it is more of a secure sandbox. The suggested approach is to download the file programmatically and then upload it to a public storage solution.

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    Was this answer helpful?

    100+ people found this answer helpful.
  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more