Model aliases
Expose stable application-level names while changing the underlying model.
AI Tools · Function
Creates a custom AI SDK provider that maps application-specific IDs to models from another provider. It can also fall back to another provider for missing models or capabilities.
customProvider builds a Provider from named model mappings. Application code retrieves models by those custom IDs, while an optional fallbackProvider can resolve models or capabilities that the custom provider does not contain.
customProvider({ languageModels?, fallbackProvider? }): Provider| Name | Type | Description |
|---|---|---|
languageModels? | Record<string, LanguageModel> | A record whose keys are custom model IDs and whose values are language model instances. |
fallbackProvider? | Provider | An optional provider used when a requested model or capability is not found in the custom provider. |
A Provider instance with methods for retrieving models by custom IDs, including languageModel and embeddingModel.
import { openai } from '@ai-sdk/openai';
import { customProvider } from 'ai';
const provider = customProvider({
languageModels: {
fast: openai('gpt-4o-mini'),
quality: openai('gpt-4o'),
},
});
const model = provider.languageModel('fast');Creates aliases for two OpenAI models, then retrieves the configured model through the custom provider.
Expose stable application-level names while changing the underlying model.
Keep approved models in a controlled mapping.
Add shared configuration around provider models.
Resolve models not present in the custom mapping.
ProviderLanguageModelembeddingModellanguageModel