Open History to see the last commit
Function: toHttpResponse()#
function toHttpResponse(stream, init?): Response;
Defined in: packages/ai/src/stream-to-response.ts:240
Convert a StreamChunk async iterable to a Response in HTTP stream format (newline-delimited JSON)
This creates a Response that emits chunks in HTTP stream format:
- Each chunk is JSON.stringify'd and followed by "\n"
- No SSE formatting (no "data: " prefix)
This format is compatible with fetchHttpStream connection adapter.
Parameters#
stream#
AsyncIterable<AGUIEvent>
AsyncIterable of StreamChunks from chat()
init?#
ResponseInit & object
Optional Response initialization options (including abortController)
Returns#
Response
Response in HTTP stream format (newline-delimited JSON)
Example#
const stream = chat({ adapter: openaiText(), model: "gpt-4o", messages: [...] });
return toHttpResponse(stream, { abortController });