Threads are not working correctly

I tried to use Threads to get answer from an Assistant that pre-created. It worked when trying in the Playground. However, when using it the the code it’s always failed. Any ideas?

OpenAI v4.91.0

Sample code:

// Read request body
    const { message } = await readBody(event)

 // Create or retrieve thread
    const thread = await openai.beta.threads.create()

// Add message to thread
    const userMessage = await openai.beta.threads.messages.create(thread.id, {
      role: 'user',
      content: message
    })

    console.log('User message:', userMessage)

     // Run the thread and wait for the result
     const run = await openai.beta.threads.runs.createAndPoll(thread.id, {
      assistant_id: String(ASSISTANT_ID),
    })

    console.log('Run:', run)

    // Get messages
    const messages = await openai.beta.threads.messages.list(run.thread_id)

  /// FAILED

The error isn’t helpful:

  last_error: { code: 'server_error', message: 'Sorry, something went wrong.' },
  model: 'gpt-4o',

Here is the project if you want to have a further look: GitHub - dalenguyen/EczEase: EczEase is a comprehensive platform designed to help individuals with eczema and food allergies manage their conditions through technology. The platform includes features like an AI chatbot, symptom tracking, naturopath directory, and educational content.

I doubt this is all the code, the code here shows nothing about the actual error message.

What are you running this in what is the environment?

That’s all the code. The error comes from the OpenAI. It’s the only error that I received.

Sorry, something went wrong.

Found the solution. The model gpt-4o doesn’t work when using Nodejs even though it works in the playground.

I tried switching the model to gpt-4o-mini-2024-07-18 and now it works :man_shrugging:

Well the reason I think this is not all the code is there is no api keys asked and no model specified in the code provided, so I lacked context where this was used in.

I am using nodejs in production and GPT-4o works allright.
I have seen the issue “Sorry, something went wrong” and there are couple of gotchas which cause it.
It is possible that the model is the reason, when we do something which the model doesn’t support, if you can eleborate on the prompt and if you had tools activated ..it could help understand the issue better.

I was using gpt-4o. Changing the model works. Not sure why.

I also have another project using gpt-4o and it works fine. Here is the sample code if you are looking for the uploading process: