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
StructuredOutputStream
type StructuredOutputStream<T> = AsyncIterable<
| Exclude<StreamChunk, CustomEvent>
| StructuredOutputStartEvent
| StructuredOutputCompleteEvent<T>>;Defined in: packages/ai/src/types.ts:1999
Public type for streams returned by chat({ outputSchema, stream: true }).
Yields all standard StreamChunk lifecycle events plus the typed structured-output CUSTOM event emitted through this path:
- structured-output.complete — terminal event with typed value.object: T
User-actionable waits, such as tool approval and client tool input, are represented by RUN_FINISHED.outcome.type === 'interrupt'.
Each variant has a literal name, so a single discriminated narrow gives you a typed value with no helper or cast:
for await (const chunk of stream) {
if (chunk.type === 'CUSTOM' && chunk.name === 'structured-output.complete') {
chunk.value.object // typed as T
}
}Caveat: tools can emit arbitrary user-defined custom events via the emitCustomEvent(name, value) context API. Those flow through this stream at runtime but are intentionally absent from this type — including a bare CustomEvent (whose value: any would poison the union) would collapse chunk.value back to any after the narrow. If you rely on emitCustomEvent plus outputSchema + stream: true, branch on CUSTOM outside the literal-name narrows or cast explicitly.
Type Parameters#
T#
T = unknown