If you are looking for an answer to this in 2025 (or later), the easiest solution would be to install the Vercel AI SDK:
npm i ai @ai-sdk/openai @ai-sdk/react zod
and follow their Expo Guide.
Contrary to their example, I was using the useObject
function instead of useChat
and thought streaming wasn't possible because the server part could not use toDataStreamResponse
. Turns out that is not true and you can achieve streaming with all the functions as long as you set up the headers to:
{
"Content-Type": "application/octet-stream",
"Content-Encoding": "none",
}
TL;DR: Just follow this guide