Skip to content


ReplicateStream(pre: Prediction, cb?: AIStreamCallbacks): Promise<ReadableStream>

The ReplicateStream function is a utility that handles extracting the stream from the output of Replicate's (opens in a new tab) API. It expects a Prediction object as returned by the Replicate JavaScript SDK (opens in a new tab), and returns a ReadableStream. Unlike other wrappers, ReplicateStream returns a Promise because it makes a fetch call to the Replicate streaming API (opens in a new tab) under the hood.


pre: Prediction

The Prediction object returned by the Replicate JavaScript SDK

cb?: AIStreamCallbacks

This optional parameter can be an object containing callback functions to handle the start, each token, and completion of the AI response. In the absence of this parameter, default behavior is implemented.


See our Replicate Guide for examples.

© 2023 Vercel Inc.