How do you unsubscribe from a streaming run?

Hi, there is documentation on how to create a subscription for a streaming run:

const run =, {
  }).on('textCreated', onTextCreated)

But there is no documentation on how or when to clean this up. I see that there are some .off methods but is it correct to call these when the run end event is complete? And will this sufficiently clean up the run? Thanks.

Welcome to the community, nikkwong! There isn’t a specific unsubscribe method for streaming runs, but you can clean them up by calling the .off('textCreated') method after processing the text. This will stop the stream and release any associated resources.

I haven’t used the JavaScript client but I think just unsubscribing will not stop the server-side stream, meaning you would still be billed for the full response. Closing the connection instead will stop the model itself.