function toServerSentEventsResponse<TOffset>(stream, init?): Response;Defined in: packages/ai/src/stream-to-response.ts:693
Convert a StreamChunk async iterable to a Response in Server-Sent Events format
This creates a Response that emits chunks in SSE format:
Pass a durability sink (memoryStream(request) / durableStream(request)) to make the stream resumable: fresh runs are appended to the log and each SSE event is tagged with an id: offset; a reconnect (native Last-Event-ID) or a ?offset join replays from the log without re-running the producer. batch controls how many chunks are buffered per append (default 32).
TOffset extends string = string
AsyncIterable<AGUIEvent>
AsyncIterable of StreamChunks from chat()
ResponseInit & object
Optional Response initialization options (including abortController, durability with its optional batch, and debug)
Response
Response in Server-Sent Events format
export async function POST(request: Request) {
const stream = chat({ adapter: openaiText('gpt-5.5'), messages: [...] });
return toServerSentEventsResponse(stream, { durability: { adapter: memoryStream(request) } });
}