Docs
CodeRabbit
Cloudflare
AG Grid
Netlify
Neon
WorkOS
Clerk
Convex
Electric
PowerSync
Sentry
Prisma
Strapi
Unkey
Fireship
CodeRabbit
Cloudflare
AG Grid
Netlify
Neon
WorkOS
Clerk
Convex
Electric
PowerSync
Sentry
Prisma
Strapi
Unkey
Fireship
Class References
Function References
Interface References
Type Alias References
Variable References
Function References

toServerSentEventsResponse

Function: toServerSentEventsResponse()

ts
function toServerSentEventsResponse(stream, init?): Response;

Defined in: stream-to-response.ts:123

Convert a StreamChunk async iterable to a Response in Server-Sent Events format

This creates a Response that emits chunks in SSE format:

  • Each chunk is prefixed with "data: "
  • Each chunk is followed by "\n\n"
  • Stream ends with "data: [DONE]\n\n"

Parameters

stream

AsyncIterable<StreamChunk>

AsyncIterable of StreamChunks from chat()

init?

ResponseInit & object

Optional Response initialization options (including abortController)

Returns

Response

Response in Server-Sent Events format

Example

typescript
const stream = chat({ adapter: openaiText(), model: "gpt-5.2", messages: [...] });
return toServerSentEventsResponse(stream, { abortController });