Openai.beta.threads.messages.create

NODEJS with “openai”: “^4.51.0”,

Creating a message as specified in the example on “Step 3” here: https://platform.openai.com/docs/assistants/overview

     const message = await openai.beta.threads.messages.create(
      threadId,
      {
        role: "user",
        content: question,
      }
    );

I got this error:
BadRequestError: 400 Unknown parameter: ‘role’.

Try without the curly braces around role and content?

curly brackets are necessary because the second parameter must be an object of type OpenAI.Beta.Threads.Messages.MessageCreateParams

I see. I meant use named parameters not positional:
…messages.create(thread_id=threadId, role=“user”, content=question)
Oops, your using nodejs. Different syntax.

I am having the same issue. And I am also using node.js. Maybe it is a bug with the node.js library?

This guys here has the same problem, and he is also using node.js:
(openai community url)/t/im-facing-issue-to-declare-user-in-theads-messages-create-in-nodejs/820728

The funny thing is that it seems random. Some times this error occurs and it suddenly stop happening without a single change in the code.

1 Like

For half an hour, I’ve also been experiencing this issue. Code that used to work fine now fails with the error message: ‘unknown parameter’.

So, I stumbled upon the same issue, but on the Ruby client side. In my case, I saw Unknown parameter: 'role'. even though role was set properly. It was the thread_id that was nil / empty.

The API error is incorrect in this case and should instead say “thread_id is null” or something similar.

I can reproduce it with this

With a wrong thread_id, it shows the correct error.

curl https://api.openai.com/v1/threads/thread_abc123/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -d '{
  "role": "user",
  "content": "How does AI work? Explain it in simple terms."
}'
{
  "error": {
    "message": "No thread found with id 'thread_abc123'.",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

With a missing thread_id, this is what it shows:

curl https://api.openai.com/v1/threads//messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -d '{
  "role": "user",
  "content": "How does AI work? Explain it in simple terms."
}'
{
  "error": {
    "message": "Unknown parameter: 'role'.",
    "type": "invalid_request_error",
    "param": "role",
    "code": "unknown_parameter"
  }
}