Assistants create threads, and an error occurs when uploading files

Here is part of my code:

  const threadId = (await openai.beta.threads.create({})).id

  const createdMessage = await openai.beta.threads.messages.create(threadId, {
    role: 'user',
    content: input.message,
    attachments:
     [
            {
              file_id: input.data.fileId,
              tools: ['file_search']
            }
          ]
      
  })

, and this is the error message:

 ⨯ node_modules/.pnpm/openai@4.38.1_encoding@0.1.13/node_modules/openai/error.mjs (41:0) @ APIError.generate
 ⨯ 400 Invalid type for 'attachments[0].tools[0]': expected an object, but got a string instead.

Welcome to the dev forum @faye_1225

It’s the error with the ["file_search"] part.

Here’s how to properly pass tools in attachments:

"attachments": [
        { "file_id": message_file.id, "tools": [{"type": "file_search"}] }
      ],

Thank you very much for your reply.

However, I have already upgraded to the latest version.openai@4.38.1.

Here is the documentation on threads: Doc
If I write it like this

"attachments": [
        { "file_id": message_file.id, "tools": [{"type": "file_search"}] }
      ],

, there will still be a type error.

TS2322: Type '{ file_id: any; tools: { type: string; }[]; }[] | undefined' is not assignable to type 'Attachment[] | null | undefined'.   Type '{ file_id: any; tools: { type: string; }[]; }[]' is not assignable to type 'Attachment[]'.     Type '{ file_id: any; tools: { type: string; }[]; }' is not assignable to type 'Attachment'.       Types of property 'tools' are incompatible.         Type '{ type: string; }[]' is not assignable to type '("file_search" | "code_interpreter")[]'.           Type '{ type: string; }' is not assignable to type '"file_search" | "code_interpreter"'. 

You need to be using tools: [{type: 'file_search'}] (without the quotes around tools and type) since you’re in Node and not python.

1 Like

Hi @nikunj , I am actually facing the same problem… and I agree with @faye_1225

so, either there is a bug on the server side or in the sdk + documentation

quick update: we downgraded to openai@4.38.0 and used the tools: [{type: 'file_search'}] approach and that works without problems.
so the issue was introduced in opeanai@4.38.1… looks like the type was updated (i think that type is better!), but the mapping to the request has a problem.

1 Like

Ah I see what’s up here. We just fixed our types in the SDK. New version just went out. Apologies for this issue.

1 Like

I’m using the assistants API. It works locally but when I run it on an Azure Web app this error occurs:

Assistants.create() got an unexpected keyword argument ‘file_ids’