📄 ai-sdk/docs/reference/ai-sdk-core/custom-provider

File: custom-provider.md | Updated: 11/15/2025

Source: https://ai-sdk.dev/docs/reference/ai-sdk-core/custom-provider

AI SDK

Menu

v5 (Latest)

AI SDK 5.x

AI SDK by Vercel

AI SDK 6 Beta

Foundations

Overview

Providers and Models

Prompts

Tools

Streaming

Getting Started

Navigating the Library

Next.js App Router

Next.js Pages Router

Svelte

Vue.js (Nuxt)

Node.js

Expo

Agents

Agents

Building Agents

Workflow Patterns

Loop Control

AI SDK Core

Overview

Generating Text

Generating Structured Data

Tool Calling

Model Context Protocol (MCP) Tools

Prompt Engineering

Settings

Embeddings

Image Generation

Transcription

Speech

Language Model Middleware

Provider & Model Management

Error Handling

Testing

Telemetry

AI SDK UI

Overview

Chatbot

Chatbot Message Persistence

Chatbot Resume Streams

Chatbot Tool Usage

Generative User Interfaces

Completion

Object Generation

Streaming Custom Data

Error Handling

Transport

Reading UIMessage Streams

Message Metadata

Stream Protocols

AI SDK RSC

Advanced

Reference

AI SDK Core

generateText

streamText

generateObject

streamObject

embed

embedMany

generateImage

transcribe

generateSpeech

tool

dynamicTool

experimental_createMCPClient

Experimental_StdioMCPTransport

jsonSchema

zodSchema

valibotSchema

ModelMessage

UIMessage

validateUIMessages

safeValidateUIMessages

createProviderRegistry

customProvider

cosineSimilarity

wrapLanguageModel

LanguageModelV2Middleware

extractReasoningMiddleware

simulateStreamingMiddleware

defaultSettingsMiddleware

stepCountIs

hasToolCall

simulateReadableStream

smoothStream

generateId

createIdGenerator

AI SDK UI

AI SDK RSC

Stream Helpers

AI SDK Errors

Migration Guides

Troubleshooting

Copy markdown

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-4': wrapLanguageModel({      model: openai('gpt-4'),      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>

A record of language models, where keys are model IDs and values are LanguageModel instances.

textEmbeddingModels?:

Record<string, EmbeddingModel<string>>

A record of text embedding models, where keys are model IDs and values are EmbeddingModel<string> instances.

imageModels?:

Record<string, ImageModel>

A record of image models, where keys are model IDs and values are ImageModelV2 instances.

fallbackProvider?:

Provider

An optional fallback provider to use when a requested model is not found in the custom provider.

Returns

The customProvider function returns a Provider instance. It has the following methods:

languageModel:

(id: string) => LanguageModel

A function that returns a language model by its id (format: providerId:modelId)

textEmbeddingModel:

(id: string) => EmbeddingModel<string>

A function that returns a text embedding model by its id (format: providerId:modelId)

imageModel:

(id: string) => ImageModel

A function that returns an image model by its id (format: providerId:modelId)

On this page

customProvider()

Example: custom model settings

Import

API Signature

Parameters

Returns

Deploy and Scale AI Apps with Vercel.

Vercel delivers the infrastructure and developer experience you need to ship reliable AI-powered applications at scale.

Trusted by industry leaders:

  • OpenAI
  • Photoroom
  • leonardo-ai Logoleonardo-ai Logo
  • zapier Logozapier Logo

Talk to an expert