function toHttpStream(
stream,
abortController?,
getId?): ReadableStream<Uint8Array<ArrayBufferLike>>;Defined in: packages/ai/src/stream-to-response.ts:1053
Convert a StreamChunk async iterable to a ReadableStream in HTTP stream format (newline-delimited JSON)
This creates a ReadableStream that emits chunks as newline-delimited JSON:
This format is compatible with fetchHttpStream connection adapter.
When getId is supplied (delivery durability), each chunk is emitted as an envelope {"id":"<offset>","chunk":{…}} instead of a bare chunk. NDJSON has no native event-id field like SSE's id: line, so the resumable offset rides inside the payload. Untagged chunks (no id) stay bare, so a non-durable stream is byte-identical to before and the client auto-detects either form.
AsyncIterable<AGUIEvent>
AsyncIterable of StreamChunks from chat()
AbortController
Optional AbortController to abort when stream is cancelled
(chunk, index) => string | undefined
Optional per-chunk durability offset; when present, chunks are envelope-encoded
ReadableStream<Uint8Array<ArrayBufferLike>>
ReadableStream in HTTP stream format (newline-delimited JSON)
const stream = chat({ adapter: openaiText('gpt-5.5'), messages: [...] });
const readableStream = toHttpStream(stream);
// Use with Response for HTTP streaming (not SSE)
return new Response(readableStream, {
headers: { 'Content-Type': 'application/x-ndjson' }
});