In some instances, you may want to simultaneously processes the LLM stream while also passing a version of it to Streamstraight. Because streams can only be consumed once, you’ll need to duplicate the stream and consume each separately.You can do so via the tee method on the ReadableStream object.
Copy
const [stream1, stream2] = llmResponseStream.tee();const ssServer = await streamstraightServer( { apiKey: process.env.STREAMSTRAIGHT_API_KEY }, { streamId: messageId },);// Stream to Streamstraight in the background asynchronously,// so you don't block the rest of this method.void ssServer.stream(stream2);// Process the stream synchronouslyfor await (const chunk of stream1) { // ...}