function extendAdapter<TFactory, TDefs>(factory, _customModels): ExtendedFactory<TFactory, TDefs>;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.
TFactory extends AnyAdapterFactory
TDefs extends readonly ExtendedModelDef<string, readonly Modality[], unknown, readonly string[], readonly string[]>[]
TFactory
The original adapter factory function (e.g., openaiText, anthropicText)
TDefs
ExtendedFactory<TFactory, TDefs>
A new factory function that accepts both original and custom models
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: [...]
})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: [...]
})