Error when uploading a batch of files sotred in a vector

I’m trying to upload stored in a vector

const fileStreams = ["knowledge.txt"].map((path) =>

  // Create a vector store including our files.
  let vectorStore = await openai.beta.vectorStores.create({
    name: "Customer queries Vector Store",

  await openai.beta.vectorStores.fileBatches.uploadAndPoll(,

I’m getting the next error:

if (files === null || files.length == 0) {

TypeError: Cannot read properties of undefined (reading ‘length’)
at FileBatches.uploadAndPoll (node_modules/openai/resources/beta/vector-stores/file-batches.js:99:37)

Node.js v20.13.1
Library v4.46.1


Were you able to resolve this? I am facing a similar problem.

Found the issue.

The uploadAndPoll method destructures the filestreams in the following fashion.

Screenshot 2024-05-14 at 5.12.18 PM

To solve this, pass the filestreams as follows

await openai.beta.vectorStores.fileBatches.uploadAndPoll(, {
files: fileStreams,

1 Like

Thanks. This seems to have worked. So, it seems like docs at is using uploadAndPoll in the wrong way.

This is how it uses it

await openai.beta.vectorStores.fileBatches.uploadAndPoll(, fileStreams)

Apparently, even the documentation can be wrong :astonished:. Now that I think of it, I have been seeing some typos around. So, I guess they’re only human.