Adapters

Model Adapters

Adapter interfaces for connecting chat models, streaming responses, and model execution to assistant-ui runtimes.

API Reference

ChatModelAdapter

ChatModelAdapter
run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult> | AsyncGenerator<ChatModelRunResult, void>

ChatModelRunOptions

ChatModelRunOptions
messages: readonly ThreadMessage[]

runConfig: RunConfig

custom?: Record<string, unknown>

abortSignal: AbortSignal

aborted: boolean

onabort: ((this:AbortSignal,ev:Event)=>any)|null

reason: any

throwIfAborted: () => void

addEventListener: { <K>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; }

removeEventListener: { <K>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; }

dispatchEvent: (event: Event) => boolean

The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent(). [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)

context: ModelContext

priority?: number

system?: string

tools?: Record<string, Tool<any, any>>

callSettings?: LanguageModelV1CallSettings

maxTokens?: number

temperature?: number

topP?: number

presencePenalty?: number

frequencyPenalty?: number

seed?: number

headers?: Record<string, string | undefined>

config?: LanguageModelConfig

apiKey?: string

baseUrl?: string

modelName?: string

unstable_assistantMessageIdunstable?: string

unstable_threadIdunstable?: string

unstable_parentIdunstable?: string | null

unstable_getMessageunstable: () => ThreadMessage

ChatModelRunResult

ChatModelRunResult
content?: readonly ThreadAssistantMessagePart[]

status?: MessageStatus

metadata?: ChatModelRunResult["metadata"]

unstable_stateunstable?: ReadonlyJSONValue

unstable_annotationsunstable?: readonly ReadonlyJSONValue[]

unstable_dataunstable?: readonly ReadonlyJSONValue[]

steps?: readonly ThreadStep[]

timing?: MessageTiming

streamStartTime: number

firstTokenTime?: number

totalStreamTime?: number

tokenCount?: number

tokensPerSecond?: number

totalChunks: number

toolCallCount: number

custom?: Record<string, unknown>

ChatModelRunUpdate

ChatModelRunUpdate
content: readonly ThreadAssistantMessagePart[]

metadata?: Record<string, unknown>

CreateResumeRunConfig

CreateResumeRunConfig
parentId: string | null

sourceId?: string | null

runConfig?: RunConfig

custom?: Record<string, unknown>

stream?: ( options: ChatModelRunOptions, ) => AsyncGenerator<ChatModelRunResult, void, unknown>

CreateStartRunConfig

CreateStartRunConfig
parentId: string | null

sourceId?: string | null

runConfig?: RunConfig

custom?: Record<string, unknown>

LanguageModelConfig

LanguageModelConfig
apiKey?: string

baseUrl?: string

modelName?: string