Data stream runtime hook and message conversion utilities for custom assistant-ui streaming backends.
API Reference
useDataStreamRuntime
useDataStreamRuntimeoptions: UseDataStreamRuntimeOptionsapi: stringprotocol?: DataStreamProtocolDefaults to response-header detection, then "ui-message-stream".
onData?: (data: { type: string; name: string; data: unknown; transient?: boolean; }) => voidCallback for data-* parts (ui-message-stream only).
onResponse?: (response: Response) => void | Promise<void>onFinish?: (message: ThreadMessage) => voidonError?: (error: Error) => voidonCancel?: () => voidcredentials?: RequestCredentialsheaders?: HeadersValue | (() => Promise<HeadersValue>)append: (name: string, value: string) => voidThe **`append()`** method of the Headers interface appends a new value onto an existing header inside a Headers object, or adds the header if it does not already exist. MDN Reference
delete: (name: string) => voidThe **`delete()`** method of the Headers interface deletes a header from the current Headers object. MDN Reference
get: (name: string) => string | nullThe **`get()`** method of the Headers interface returns a byte string of all the values of a header within a Headers object with a given name. If the requested header doesn't exist in the Headers object, it returns null. MDN Reference
getSetCookie: () => string[]The **`getSetCookie()`** method of the Headers interface returns an array containing the values of all Set-Cookie headers associated with a response. This allows Headers objects to handle having multiple Set-Cookie headers, which wasn't possible prior to its implementation. MDN Reference
has: (name: string) => booleanThe **`has()`** method of the Headers interface returns a boolean stating whether a Headers object contains a certain header. MDN Reference
set: (name: string, value: string) => voidThe **`set()`** method of the Headers interface sets a new value for an existing header inside a Headers object, or adds the header if it does not already exist. MDN Reference
forEach: (callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any) => voidentries: () => HeadersIterator<[string, string]>Returns an iterator allowing to go through all key/value pairs contained in this object.
keys: () => HeadersIterator<string>Returns an iterator allowing to go through all keys of the key/value pairs contained in this object.
values: () => HeadersIterator<string>Returns an iterator allowing to go through all values of the key/value pairs contained in this object.
body?: object | (() => Promise<object | undefined>)sendExtraMessageFields?: booleanmaxSteps?: numberunstable_humanToolNamesunstable?: string[]Names of tools that pause the run until a result is supplied via `addToolResult`.
unstable_enableMessageQueueunstable?: booleanOpt in to message queuing: a message sent during a run is held in `composer.queue` and sent once the run settles. Steering runs it next.
cloud?: AssistantCloudthreads: AssistantCloudThreadsmessages: AssistantCloudThreadMessagescloud: AssistantCloudAPIlist: (query?: AssistantCloudThreadsListQuery) => Promise<AssistantCloudThreadsListResponse>get: (threadId: string) => Promise<CloudThread>create: (body: AssistantCloudThreadsCreateBody) => Promise<AssistantCloudThreadsCreateResponse>update: (threadId: string, body: AssistantCloudThreadsUpdateBody) => Promise<void>delete: (threadId: string) => Promise<void>
auth: __objecttokens: AssistantCloudAuthTokens
runs: AssistantCloudRunscloud: AssistantCloudAPIstream: (body: AssistantCloudRunsStreamBody) => Promise<AssistantStream>report: (body: AssistantCloudRunReport) => Promise<{ run_id: string; }>
files: AssistantCloudFilescloud: AssistantCloudAPIpdfToImages: (body: PdfToImagesRequestBody) => Promise<PdfToImagesResponse>generatePresignedUploadUrl: (body: GeneratePresignedUploadUrlRequestBody) => Promise<GeneratePresignedUploadUrlResponse>
telemetry: AssistantCloudTelemetryConfigenabled?: booleanbeforeReport?: ( report: AssistantCloudRunReport, ) => AssistantCloudRunReport | nullCalled before each telemetry report is sent. Return a modified report to enrich it (e.g. add `model_id`), or return `null` to skip the report.
initialMessages?: readonly ThreadMessageLike[]adapters?: Omit<LocalRuntimeOptionsBase["adapters"], "chatModel">attachments?: AttachmentAdapteraccept: stringadd: (state: { file: File; }) => Promise<PendingAttachment> | AsyncGenerator<PendingAttachment, void>remove: (attachment: Attachment) => Promise<void>send: (attachment: PendingAttachment) => Promise<CompleteAttachment>
suggestion?: SuggestionAdaptergenerate: ( options: SuggestionAdapterGenerateOptions, ) => | Promise<readonly ThreadSuggestion[]> | AsyncGenerator<readonly ThreadSuggestion[], void>
dictation?: DictationAdapterlisten: () => DictationAdapter.SessiondisableInputDuringDictation?: boolean
speech?: SpeechSynthesisAdapterspeak: (text: string) => SpeechSynthesisAdapter.Utterance
voice?: RealtimeVoiceAdapterconnect: (options: { abortSignal?: AbortSignal; }) => RealtimeVoiceAdapter.Session
feedback?: FeedbackAdaptersubmit: (feedback: FeedbackAdapterFeedback) => void
history?: ThreadHistoryAdapterload: () => Promise<ExportedMessageRepository & { state?: ReadonlyJSONValue; unstable_resume?: boolean; }>resume?: (options: ChatModelRunOptions) => AsyncGenerator<ChatModelRunResult, void, unknown>append: (item: ExportedMessageRepositoryItem) => Promise<void>delete?: (items: ExportedMessageRepositoryItem[]) => Promise<void>withFormat?: <TMessage, TStorageFormat extends Record<string, unknown>>(formatAdapter: MessageFormatAdapter<TMessage, TStorageFormat>) => GenericThreadHistoryAdapter<TMessage>Required when used with `useAISDKRuntime` / `useChatRuntime`.
toLanguageModelMessages
Deprecated. Use toGenericMessages from assistant-stream for framework-agnostic conversion.
This function is kept for AI SDK compatibility.
toLanguageModelMessagesmessages: readonly ThreadMessage[]options?: { unstable_includeId?: boolean | undefined; }unstable_includeIdunstable?: boolean
useCloudRuntime
Deprecated. This is under active development and not yet ready for prod use.
useCloudRuntimeoptions: UseCloudRuntimeOptionsbody?: object | (() => Promise<object | undefined>)onError?: (error: Error) => voidonCancel?: () => voidadapters?: Omit<LocalRuntimeOptionsBase["adapters"], "chatModel">attachments?: AttachmentAdapteraccept: stringadd: (state: { file: File; }) => Promise<PendingAttachment> | AsyncGenerator<PendingAttachment, void>remove: (attachment: Attachment) => Promise<void>send: (attachment: PendingAttachment) => Promise<CompleteAttachment>
suggestion?: SuggestionAdaptergenerate: ( options: SuggestionAdapterGenerateOptions, ) => | Promise<readonly ThreadSuggestion[]> | AsyncGenerator<readonly ThreadSuggestion[], void>
dictation?: DictationAdapterlisten: () => DictationAdapter.SessiondisableInputDuringDictation?: boolean
speech?: SpeechSynthesisAdapterspeak: (text: string) => SpeechSynthesisAdapter.Utterance
voice?: RealtimeVoiceAdapterconnect: (options: { abortSignal?: AbortSignal; }) => RealtimeVoiceAdapter.Session
feedback?: FeedbackAdaptersubmit: (feedback: FeedbackAdapterFeedback) => void
history?: ThreadHistoryAdapterload: () => Promise<ExportedMessageRepository & { state?: ReadonlyJSONValue; unstable_resume?: boolean; }>resume?: (options: ChatModelRunOptions) => AsyncGenerator<ChatModelRunResult, void, unknown>append: (item: ExportedMessageRepositoryItem) => Promise<void>delete?: (items: ExportedMessageRepositoryItem[]) => Promise<void>withFormat?: <TMessage, TStorageFormat extends Record<string, unknown>>(formatAdapter: MessageFormatAdapter<TMessage, TStorageFormat>) => GenericThreadHistoryAdapter<TMessage>Required when used with `useAISDKRuntime` / `useChatRuntime`.
maxSteps?: numberunstable_humanToolNamesunstable?: string[]Names of tools that pause the run until a result is supplied via `addToolResult`.
unstable_enableMessageQueueunstable?: booleanOpt in to message queuing: a message sent during a run is held in `composer.queue` and sent once the run settles. Steering runs it next.
headers?: HeadersValue | (() => Promise<HeadersValue>)append: (name: string, value: string) => voidThe **`append()`** method of the Headers interface appends a new value onto an existing header inside a Headers object, or adds the header if it does not already exist. MDN Reference
delete: (name: string) => voidThe **`delete()`** method of the Headers interface deletes a header from the current Headers object. MDN Reference
get: (name: string) => string | nullThe **`get()`** method of the Headers interface returns a byte string of all the values of a header within a Headers object with a given name. If the requested header doesn't exist in the Headers object, it returns null. MDN Reference
getSetCookie: () => string[]The **`getSetCookie()`** method of the Headers interface returns an array containing the values of all Set-Cookie headers associated with a response. This allows Headers objects to handle having multiple Set-Cookie headers, which wasn't possible prior to its implementation. MDN Reference
has: (name: string) => booleanThe **`has()`** method of the Headers interface returns a boolean stating whether a Headers object contains a certain header. MDN Reference
set: (name: string, value: string) => voidThe **`set()`** method of the Headers interface sets a new value for an existing header inside a Headers object, or adds the header if it does not already exist. MDN Reference
forEach: (callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any) => voidentries: () => HeadersIterator<[string, string]>Returns an iterator allowing to go through all key/value pairs contained in this object.
keys: () => HeadersIterator<string>Returns an iterator allowing to go through all keys of the key/value pairs contained in this object.
values: () => HeadersIterator<string>Returns an iterator allowing to go through all values of the key/value pairs contained in this object.
cloud: AssistantCloudthreads: AssistantCloudThreadsmessages: AssistantCloudThreadMessagescloud: AssistantCloudAPIlist: (query?: AssistantCloudThreadsListQuery) => Promise<AssistantCloudThreadsListResponse>get: (threadId: string) => Promise<CloudThread>create: (body: AssistantCloudThreadsCreateBody) => Promise<AssistantCloudThreadsCreateResponse>update: (threadId: string, body: AssistantCloudThreadsUpdateBody) => Promise<void>delete: (threadId: string) => Promise<void>
auth: __objecttokens: AssistantCloudAuthTokens
runs: AssistantCloudRunscloud: AssistantCloudAPIstream: (body: AssistantCloudRunsStreamBody) => Promise<AssistantStream>report: (body: AssistantCloudRunReport) => Promise<{ run_id: string; }>
files: AssistantCloudFilescloud: AssistantCloudAPIpdfToImages: (body: PdfToImagesRequestBody) => Promise<PdfToImagesResponse>generatePresignedUploadUrl: (body: GeneratePresignedUploadUrlRequestBody) => Promise<GeneratePresignedUploadUrlResponse>
telemetry: AssistantCloudTelemetryConfigenabled?: booleanbeforeReport?: ( report: AssistantCloudRunReport, ) => AssistantCloudRunReport | nullCalled before each telemetry report is sent. Return a modified report to enrich it (e.g. add `model_id`), or return `null` to skip the report.
initialMessages?: readonly ThreadMessageLike[]onFinish?: (message: ThreadMessage) => voidonData?: (data: { type: string; name: string; data: unknown; transient?: boolean; }) => voidCallback for data-* parts (ui-message-stream only).
protocol?: DataStreamProtocolDefaults to response-header detection, then "ui-message-stream".
onResponse?: (response: Response) => void | Promise<void>credentials?: RequestCredentialssendExtraMessageFields?: booleanassistantId: string