createProviderRegistry()
When you work with multiple providers and models, it is often desirable to manage them in a central place and access the models through simple string ids.
createProviderRegistry lets you create a registry with multiple providers that you
can access by their ids in the format providerId:modelId.
In TypeScript, registry model IDs are inferred from the registered provider IDs.
When a provider exposes literal model ID types, editors can suggest the combined
providerId:modelId values.
Setup
You can create a registry with multiple providers and models using createProviderRegistry.
import { anthropic } from '@ai-sdk/anthropic';import { createOpenAI } from '@ai-sdk/openai';import { createProviderRegistry } from 'ai';
export const registry = createProviderRegistry({ // register provider with prefix and default setup: anthropic,
// register provider with prefix and custom setup: openai: createOpenAI({ apiKey: process.env.OPENAI_API_KEY, }),});Custom Separator
By default, the registry uses : as the separator between provider and model IDs. You can customize this separator by passing a separator option:
const registry = createProviderRegistry( { anthropic, openai, }, { separator: ' > ' },);
// Now you can use the custom separatorconst model = registry.languageModel('anthropic > claude-3-opus-20240229');Language models
You can access language models by using the languageModel method on the registry.
The provider id will become the prefix of the model id: providerId:modelId.
import { generateText } from 'ai';import { registry } from './registry';
const { text } = await generateText({ model: registry.languageModel('openai:gpt-4.1'), prompt: 'Invent a new holiday and describe its traditions.',});Text embedding models
You can access text embedding models by using the .embeddingModel method on the registry.
The provider id will become the prefix of the model id: providerId:modelId.
import { embed } from 'ai';import { registry } from './registry';
const { embedding } = await embed({ model: registry.embeddingModel('openai:text-embedding-3-small'), value: 'sunny day at the beach',});Image models
You can access image models by using the imageModel method on the registry.
The provider id will become the prefix of the model id: providerId:modelId.
import { generateImage } from 'ai';import { registry } from './registry';
const { image } = await generateImage({ model: registry.imageModel('openai:dall-e-3'), prompt: 'A beautiful sunset over a calm ocean',});Video models
You can access video models by using the videoModel method on the registry.
The provider id will become the prefix of the model id: providerId:modelId.
import { fal } from '@ai-sdk/fal';import { createProviderRegistry, experimental_generateVideo } from 'ai';
const registry = createProviderRegistry({ fal });
const { videos } = await experimental_generateVideo({ model: registry.videoModel('fal:luma-dream-machine/ray-2'), prompt: 'A cat walking on a beach at sunset',});Files and skills
You can access a provider's files and skills interfaces by calling
registry.files(providerId) and registry.skills(providerId).
Import
import { createProviderRegistry } from "ai"API Signature
Parameters
providers:
languageModel:
embeddingModel:
imageModel:
transcriptionModel?:
speechModel?:
rerankingModel?:
videoModel?:
files?:
skills?:
options?:
separator?:
languageModelMiddleware?:
imageModelMiddleware?:
Returns
The createProviderRegistry function returns a Provider instance. It has the following methods: