Do you need to pass ""stream": true" to start streaming?

In the api reference for assistants streaming it indicates here that:

You can stream events from the Create Thread and Run, Create Run, and Submit Tool Outputs endpoints by passing "stream": true . The response will be a Server-Sent events stream.

I don’t really see anywhere showing someone passing that when using streaming. Is it the same as flush=True from these streaming helpers?

The sample shown in the documentation page uses stream SDK. It is confusing since they appear the same function as in the API Reference page. When you use the vanilla/generic function, use stream: true property.

with stream SDK

const run = openai.beta.threads.runs.stream(thread.id, {
    assistant_id: assistant.id
  })
    .on('textCreated', (text) => process.stdout.write('\nassistant > '))
    .on('textDelta', (textDelta, snapshot) => process.stdout.write(textDelta.value))
...

vanilla/generic function (uses stream:true)

const stream = await openai.beta.threads.runs.create(
    "thread_123",
    { assistant_id: "asst_123", stream: true }
  );

  for await (const event of stream) {
    console.log(event);
  }
2 Likes

That’s right – when you use the .stream SDK helper, we automatically pass the stream = true parameter for you.

You only need to manually pass stream = true when using the generic .create (and other similar endpoints). These SDK helpers are documented here: openai-node/helpers.md at master · openai/openai-node · GitHub

2 Likes