This is a simple repost of List and delete all threads - #4 by jkyle
Much thanks to jkyle and sashirestela for the demonstration.
- Open the developer tools in Chrome and activate the Network tab.
- Navigate to https://platform.openai.com/assistants
- With the network tab shown, reload the page and capture the requests
- Under assistants?limit=10 find the ‘Request Headers’ section > ‘Authorization’
- Copy ‘sess-…’ and your organization ID.
import requests as req
from alive_progress import alive_it
from openai import OpenAI
import time
client = OpenAI()
token = 'sess-...'
org = 'org-...'
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']]
This will sequentially delete all your existing threads.