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
extendAdapter
function extendAdapter<TFactory, TDefs>(factory, _customModels): ExtendedFactory<TFactory, TDefs>;Defined in: packages/ai/src/extend-adapter.ts:247
Extends an existing adapter factory with additional custom models.
The extended adapter accepts both original models (with full original type inference) and custom models (with types from your definitions).
At runtime, this simply passes through to the original factory - no validation is performed. The original factory's signature is fully preserved, including any config parameters.
Type Parameters#
TFactory#
TFactory extends AnyAdapterFactory
TDefs#
TDefs extends readonly ExtendedModelDef<string, readonly ("text" | "image" | "audio" | "video" | "document")[], unknown, readonly string[], readonly string[]>[]
Parameters#
factory#
TFactory
The original adapter factory function (e.g., openaiText, anthropicText)
_customModels#
TDefs
Returns#
ExtendedFactory<TFactory, TDefs>
A new factory function that accepts both original and custom models
Example#
import { extendAdapter, createModel } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
// Define custom models
const customModels = [
createModel('my-fine-tuned-gpt4', ['text', 'image']),
createModel('local-llama', ['text']),
] as const
// Create extended adapter
const myOpenai = extendAdapter(openaiText, customModels)
// Use with original models - full type inference preserved
const gpt4 = myOpenai('gpt-4o')
// Use with custom models
const custom = myOpenai('my-fine-tuned-gpt4')
// Type error: 'invalid-model' is not a valid model
// myOpenai('invalid-model')
// Works with chat()
chat({
adapter: myOpenai('my-fine-tuned-gpt4'),
messages: [...]
})