How to DELETE threads with GPT-4o and assistants

Hello. I am using GPT-4o with assistants (v2). I have an app that uploads text and asks GPT-4o to analyse the text using criteria I supply to the assistant. When the processing is done I want to programmatically DELETE the threads because they mount up and become a huge amount of unwanted data if I don’t, but I can’t see a way to bulk delete all threads. Any help from OpenAI or elsewhere would be HUGELY appreciated. I am working in python.

Threads cannot be listed by API key, a measure to prevent eavesdropping by other organization members. That precludes a bulk delete by conventional methods of listing and processing (which would be dangerous anyway).

Since you can’t list them, leaving a whole bunch of garbage behind isn’t really a penalty to you, and inactive ones are removed after 60 days.

Instead you should use your own management. If a user deletes their chat in a user interface, you delete the thread. If a user logs in and you load your own storage of their chats, go through and delete the ones automatically on both sides that are no longer serviceable.

Many thanks for your swift advice. Thing is I simply want to delete threads (I have one unique thread per query to a vector store) after the processing is done and I thought I had done that, but the thread persist. And in my case, add up to thousands in a heart beat. So a different question; how can I totally delete a thread after using it? So that it won’t be stored anywhere on OpenAI?

This is the “totally delete” method, using http DELETE instead of POST or GET.

delete https://api.openai.com/v1/threads/{thread_id}

Returning:

{
  "id": "thread_abc123aeaDFN3nfD3..",
  "object": "thread.deleted",
  "deleted": true
}

The period of storage by OpenAI for other safety systems is by terms and conditions.

In general, there is no NATIVE method to list threads. HOWEVER with clever use of metadata, you can list threads and ofc then programmtically delete them.

>>> from bmodels import AutoExecThread
>>> AutoExecThread.create()
[AutoExecBaseThread(thread_id='thread_pL5Vs3dPmDt7el4KuGzr1cNW')]
>>> AutoExecThread.list()
[AutoExecBaseThread(thread_id='thread_pL5Vs3dPmDt7el4KuGzr1cNW')]
>>> AutoExecThread.create()
[AutoExecBaseThread(thread_id='thread_pL5Vs3dPmDt7el4KuGzr1cNW'), AutoExecBaseThread(thread_id='thread_dIuaNGllXPhoZLO6gFyyK6H3')]
>>> AutoExecThread.list()
[AutoExecBaseThread(thread_id='thread_pL5Vs3dPmDt7el4KuGzr1cNW'), AutoExecBaseThread(thread_id='thread_dIuaNGllXPhoZLO6gFyyK6H3')]

However, with clever use of Oauth2 and session keys, you can navigate an entire account’s organizations and projects hierarchy and purge everything.

“cannot be listed by API key” was a thoughtful constraint on what can be done.

:slight_smile:
sure.

But the ops question was different. Can the threads be programmatically listed (and then be deleted) with GPT-4o and assistant? The above was the answer to that question. In this solution, I just make use of metadata provided in the assistants and threads.

The “thoughtful” constraint also constraints certain solutions.

1 Like

Thank you SO much for your advice. Very generous of you to help. I will try that solution.

Thanks for your contribution. Appreciated.

where do you get the ‘bmodels’ pkg?

I had to make selfet (which contains the implementation of AutoExecThread) to be temporarily private because the multi-agent framework needed a little refactoring. Just turned back the visibility to public.

In that refactoring, the AutoExecThread is defined here: selfet/src/backend/bmodels/threads/main.py at main · icdev2dev/selfet · GitHub

Obviously this, in context of the overall post, is merely illustrative. You might want to look at the implementation of AutoExecThread and roll your own by using the betaassi framework.