Stream HelpersOpenAIStream
OpenAIStream
Transforms the response from OpenAI's language models into a ReadableStream.
Note: Prior to v4, the official OpenAI API SDK does not support the Edge Runtime and only works in serverless environments. The openai-edge package is based on fetch instead of axios (and thus works in the Edge Runtime) so we recommend using openai v4+ or openai-edge.
Import
React
import { OpenAIStream } from "ai"
Parameters
response:
The response object returned by a call made by the Provider SDK.
callback?:
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.
Returns
A ReadableStream.