skip to Main Content

What is a workaround to list all thread IDs from the OpenAI developer platform (https://platform.openai.com/threads/) using JavaScript?

There is no official API to list all available threads.

I found answers about the v1 API. It’s also possible to list messages for a given thread, but that’s not what is needed.

Sources:

2

Answers


  1. Chosen as BEST ANSWER

    After long day searching, found a way to get a list of all threads available on OpenAI developer platform dashboard threads page (https://platform.openai.com/threads).

    1. Go to threads page (must be logged in).
    2. Open Developer Tools inside browser.
    3. Paste js code in console
    const html = document.body.innerHTML;
    const threadIdRegex = /thread_[A-Za-z0-9]+/g; // Regular expression to match thread IDs
    const threadIds = html.match(threadIdRegex) || [];
    const threadIdsSet = new Set(threadIds);
    
    console.log(threadIdsSet);
    

    Now you have a list of all threads that you can use further in your application.

    Example use. WARNING! All data would be deleted, use with caution!

    Delete all threads on OpenAI threads page:

    const = ['thread_123...', ...]
    
    for (const threadId of threadList) {
      openai.beta.threads.del(threadId)
    }
    

  2. No, you cannot list an existing thread via the Assistants API if you didn’t store the thread ID when creating it.

    You can:

    The https://api.openai.com/v1/threads API endpoint suggested in the comment above is to create a thread.

    Also, retrieving a thread is not what you’re looking for because you need to pass the thread ID to the API endpoint. There’s no way to list existing thread IDs via the Assistants API.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search