Issues with Assistant API + threads

If i understand the API correctly, there is no automatic thread management. So this line will always create a new thread every single time it’s called.

 // Create a new thread for each conversation
const threadResponse = await openai.beta.threads.create();

so each time you call askGPT, a new thread is created.

There does not seem to be any method/API for getting a list of created Threads, which means that you need to store the thread id on your side to a database.

So instead of always calling create(), you need to check if a thread id exists in your database, then fetch it with openai.beta.threads.retrieve(thread_id). And if it doesn’t exist, then create a new thread.

2 Likes