content/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx
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.
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,
});
<Snippet text={import { customProvider } from "ai"} prompt={false} />
<PropertiesTable content={[ { name: 'languageModels', type: 'Record<string, LanguageModel>', isOptional: true, description: 'A record of language models, where keys are model IDs and values are LanguageModel instances.', }, { name: '.embeddingModels', type: 'Record<string, EmbeddingModel<string>>', isOptional: true, description: 'A record of text embedding models, where keys are model IDs and values are EmbeddingModel<string> instances.', }, { name: 'imageModels', type: 'Record<string, ImageModel>', isOptional: true, description: 'A record of image models, where keys are model IDs and values are image model instances.', }, { name: 'transcriptionModels', type: 'Record<string, TranscriptionModel>', isOptional: true, description: 'A record of transcription models, where keys are model IDs and values are TranscriptionModel instances.', }, { name: 'speechModels', type: 'Record<string, SpeechModel>', isOptional: true, description: 'A record of speech models, where keys are model IDs and values are SpeechModel instances.', }, { name: 'rerankingModels', type: 'Record<string, RerankingModel>', isOptional: true, description: 'A record of reranking models, where keys are model IDs and values are RerankingModel instances.', }, { name: 'fallbackProvider', type: 'Provider', isOptional: true, description: 'An optional fallback provider to use when a requested model is not found in the custom provider.', }, ]} />
The customProvider function returns a Provider instance. It has the following methods:
<PropertiesTable content={[ { name: 'languageModel', type: '(id: string) => LanguageModel', description: 'A function that returns a language model by its id (format: providerId:modelId)', }, { name: 'embeddingModel', type: '(id: string) => EmbeddingModel<string>', description: 'A function that returns a text embedding model by its id (format: providerId:modelId)', }, { name: 'imageModel', type: '(id: string) => ImageModel', description: 'A function that returns an image model by its id (format: providerId:modelId)', }, { name: 'transcriptionModel', type: '(id: string) => TranscriptionModel', description: 'A function that returns a transcription model by its id.', }, { name: 'speechModel', type: '(id: string) => SpeechModel', description: 'A function that returns a speech model by its id.', }, { name: 'rerankingModel', type: '(id: string) => RerankingModel', description: 'A function that returns a reranking model by its id.', }, ]} />