How to stream response in javascript?

It seems like you can use stream: true for the regular POST completion endpoint but use this library:

They actually recommend it in the documentation:

If you’d like to stream results from the POST variant in your browser, consider using the SSE library.

If you look into the code, it seems like it’s listening to the progress event when opening up an XHR instance and then parsing that data into tokens, so I’m guessing setting stream: true in the POST request case is just enabling chunked transfer encoding on the response.

Since streaming responses on a POST request can happen on the server, I would personally opt for that so you don’t have to disclose your private key to anyone on the client (if you plan on shipping what you’re working on to users) vs. using server sent events or any browser implementation.