Class References
Function References
- text
- textOptions
- combineStrategies
- convertMessagesToModelMessages
- convertZodToJsonSchema
- createReplayStream
- embedding
- generateMessageId
- maxIterations
- messages
- modelMessageToUIMessage
- modelMessagesToUIMessages
- normalizeToUIMessage
- parsePartialJSON
- summarize
- toServerSentEventsStream
- toServerSentEventsResponse
- toolDefinition
- uiMessageToModelMessages
- realtimeToken
- untilFinishReason
Interface References
- AIAdapter
- AIAdapterConfig
- AgentLoopState
- AudioPart
- AudioVisualization
- BaseStreamChunk
- TextCompletionChunk
- TextOptions
- ChunkRecording
- ChunkStrategy
- ClientTool
- ContentPartSource
- ContentStreamChunk
- DefaultMessageMetadataByModality
- DocumentPart
- DoneStreamChunk
- EmbeddingOptions
- EmbeddingResult
- ErrorStreamChunk
- ImagePart
- InternalToolCallState
- JSONParser
- ModelMessage
- ProcessorResult
- ProcessorState
- RealtimeAdapter
- RealtimeClientOptions
- RealtimeConnection
- RealtimeMessage
- RealtimeSessionConfig
- RealtimeToken
- RealtimeTokenAdapter
- RealtimeTokenOptions
- ResponseFormat
- ServerTool
- StreamProcessorEvents
- StreamProcessorHandlers
- StreamProcessorOptions
- SummarizationOptions
- SummarizationResult
- TextPart
- ThinkingPart
- ThinkingStreamChunk
- Tool
- ToolCall
- ToolCallPart
- ToolCallStreamChunk
- ToolConfig
- ToolDefinition
- ToolDefinitionConfig
- ToolDefinitionInstance
- ToolInputAvailableStreamChunk
- ToolResultPart
- ToolResultStreamChunk
- UIMessage
- VideoPart
Type Alias References
- AgentLoopStrategy
- AnyClientTool
- TextStreamOptionsForModel
- TextStreamOptionsUnion
- ConstrainedContent
- ConstrainedModelMessage
- ContentPart
- ContentPartForModalities
- ExtractModalitiesForModel
- ExtractModelsFromAdapter
- InferToolInput
- InferToolName
- InferToolOutput
- MessagePart
- RealtimeEvent
- RealtimeMessagePart
- RealtimeMode
- RealtimeStatus
- ModalitiesArrayToUnion
- Modality
- StreamChunk
- ToolCallState
- ToolResultState
Variable References
toHttpStream
function toHttpStream(
stream,
abortController?,
getId?): ReadableStream<Uint8Array<ArrayBufferLike>>;Defined in: packages/ai/src/stream-to-response.ts:1416
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:
- Each chunk is JSON.stringify'd and followed by "\n"
- No SSE formatting (no "data: " prefix)
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.
Parameters#
stream#
AsyncIterable<AGUIEvent>
AsyncIterable of StreamChunks from chat()
abortController?#
AbortController
Optional AbortController to abort when stream is cancelled
getId?#
(chunk, index) => string | undefined
Optional per-chunk durability offset; when present, chunks are envelope-encoded
Returns#
ReadableStream<Uint8Array<ArrayBufferLike>>
ReadableStream in HTTP stream format (newline-delimited JSON)
Example#
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' }
});