List and delete all threads

Using the python requests library and the session token from above, this looks like…

import requests as req

url = "https://api.openai.com/v1/threads"
headers = {
    "Authorization": f"Bearer {token}", 
    "Openai-Organization": f"{org}", 
    "OpenAI-Beta": "assistants=v1"
}

resp = req.get(url, headers=headers)

A full script to delete all threads:

import requests as req
from alive_progress import alive_it

token = "the_token"
org = "myorg"
url = "https://api.openai.com/v1/threads"

headers = {
    "Authorization": f"Bearer {token}", 
    "Openai-Organization": f"{org}", 
    "OpenAI-Beta": "assistants=v1"
}
params = {"limit": 10}
resp = req.get(url, headers=headers, params=params)
ids = [t['id'] for t in resp.json()['data']]

while len(ids) > 0:
    for tid in alive_it(ids, force_tty=True):
        client.beta.threads.delete(tid)
        time.sleep(1)
    resp = req.get(url, headers=headers, params=params)
    ids = [t['id'] for t in resp.json()['data']]

6 Likes