You can use the pipeUIMessageStreamToResponse method to pipe the stream data to the server response.
index.ts
import { streamText } from 'ai';import { createServer } from 'http';createServer(async (req, res) => { const result = streamText({ model: 'openai/gpt-4o', prompt: 'Invent a new holiday and describe its traditions.', }); result.pipeUIMessageStreamToResponse(res);}).listen(8080);
You can send a text stream to the client using pipeTextStreamToResponse.
index.ts
import { streamText } from 'ai';import { createServer } from 'http';createServer(async (req, res) => { const result = streamText({ model: 'openai/gpt-4o', prompt: 'Invent a new holiday and describe its traditions.', }); result.pipeTextStreamToResponse(res);}).listen(8080);