Streaming
How to get real-time feedback from workflows
NOTE: THIS PAGE IS UNDER CONSTRUCTION FOR OUR NEW STREAMING TECHNIQUE. Please contact [email protected] if you are urgently working to implement streaming.
Tennr workflows with text output support streaming the results back to the client as each token is generated. This is useful for ensuring rapid visual feedback for users, particularly in chat applications.
However, there is a noticeable increase in complexity when handling these streamed results on the client side. This document aims to provide some guidance on how to handle these results with examples from our own frontends.
In order to trigger streaming at the workflow run endpoint, you must set the stream
parameter to true
in the request body.
Next.js
The following code shows an example of how to call the API in stream mode and how to parse and handle the messages as they are received from the backend.
Notice that we parse two types of data, normal responses and the sources object. The sources object is returned after all normal message content is sent, and its example structure can be seen below.
We recommend combining this code with state management callbacks (onDataReceived and onSourcesReceived in our example) to update your UI as new content is delivered.