customProvider()
With a custom provider, you can map ids to any model. This allows you to set up custom model configurations, alias names, and more. The custom provider also supports a fallback provider, which is useful for wrapping existing providers and adding additional functionality.
Example: custom model settings
You can create a custom provider using customProvider.
import { openai } from '@ai-sdk/openai';import { customProvider } from 'ai';
// custom provider with different model settings:export const myOpenAI = customProvider({ languageModels: { // replacement model with custom settings: 'gpt-5': wrapLanguageModel({ model: openai('gpt-5'), middleware: defaultSettingsMiddleware({ settings: { providerOptions: { openai: { reasoningEffort: 'high', }, }, }, }), }), // alias model with custom settings: 'gpt-4o-reasoning-high': wrapLanguageModel({ model: openai('gpt-4o'), middleware: defaultSettingsMiddleware({ settings: { providerOptions: { openai: { reasoningEffort: 'high', }, }, }, }), }), }, fallbackProvider: openai,});Import
import { customProvider } from "ai"API Signature
Parameters
languageModels?:
Record<string, LanguageModel>
.embeddingModels?:
Record<string, EmbeddingModel<string>>
imageModels?:
Record<string, ImageModel>
transcriptionModels?:
Record<string, TranscriptionModel>
speechModels?:
Record<string, SpeechModel>
rerankingModels?:
Record<string, RerankingModel>
fallbackProvider?:
Provider
Returns
The customProvider function returns a Provider instance. It has the following methods:
languageModel:
(id: string) => LanguageModel
embeddingModel:
(id: string) => EmbeddingModel<string>
imageModel:
(id: string) => ImageModel
transcriptionModel:
(id: string) => TranscriptionModel
speechModel:
(id: string) => SpeechModel
rerankingModel:
(id: string) => RerankingModel