function toHttpResponse<TOffset>(stream, init?): Response;Defined in: packages/ai/src/stream-to-response.ts:1118
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:
This format is compatible with fetchHttpStream connection adapter.
Pass a durability sink (memoryStream(request) / durableStream(request)) to make the stream resumable: fresh runs are appended to the log and each NDJSON line is emitted as an { id, chunk } envelope carrying an opaque offset; a reconnect (native Last-Event-ID header) or a ?offset join replays from the log without re-running the producer. batch controls how many chunks are buffered per append (default 32). This shares the exact durableStreamSource used by toServerSentEventsResponse — only the wire encoding differs.
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 HTTP stream format (newline-delimited JSON)
export async function POST(request: Request) {
const stream = chat({ adapter: openaiText('gpt-5.5'), messages: [...] });
return toHttpResponse(stream, { durability: { adapter: memoryStream(request) } });
}