Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Function

createProviderRegistry

Creates a registry for multiple providers and models. Registered models are retrieved with provider-qualified IDs such as providerId:modelId.

How it works

createProviderRegistry builds a central provider registry from a mapping of unique provider identifiers to providers. The returned provider exposes methods such as languageModel and embeddingModel, which resolve registered models from identifiers formatted as providerId:modelId.

Syntax

createProviderRegistry(providers: Record<string, Provider>): Provider

Parameters

NameTypeDescription
providersRecord<string, Provider>A record mapping unique provider identifiers to Provider instances.

Returns

A Provider instance with languageModel and embeddingModel methods.

Key points

  • Use one registry to organize models from several providers behind a shared lookup surface.
  • Each provider key must be unique within the registry.
  • languageModel resolves a registered language model from its provider-qualified identifier.
  • embeddingModel resolves text embedding models using the same provider-qualified identifier pattern.

Common mistakes

  • Model lookups must include the provider prefix, such as openai:gpt-4o, rather than only the model name.

Example: Register and resolve providers

import { createProviderRegistry } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import { openai } from '@ai-sdk/openai';

const registry = createProviderRegistry({ anthropic, openai });
const model = registry.languageModel('openai:gpt-4o');

Registers providers under their object keys, then resolves a language model with the provider:model identifier format.

When to use it

Centralize provider configuration

An application supports models from multiple vendors and needs one consistent lookup mechanism.

Resolve models by qualified ID

Runtime configuration selects a model using a string identifier such as openai:gpt-4o.

Manage language and embedding models

A service needs both chat models and text embedding models from registered providers.

Interview questions

QWhat problem does createProviderRegistry solve?

It creates a registry that combines multiple providers and models behind one provider interface. Each provider is registered under an identifier, and models are selected with identifiers in the form providerId:modelId.

Follow-up: How would you retrieve a text embedding model? Use the registry's embeddingModel method with the corresponding providerId:modelId string.

QWhat does the function accept and return?

The argument is a record whose keys identify providers and whose values are Provider instances. Provider identifiers should be unique within the registry so model resolution remains unambiguous.

Follow-up: What does the returned object provide? It is a Provider instance with model-resolution methods, including languageModel and embeddingModel.

QHow are models resolved from the registry?

Call languageModel with a string such as openai:gpt-4o; the provider portion selects the registered provider and the remaining portion identifies its model. The registry also supports embeddingModel for text embedding models.

Follow-up: What naming convention is used? The provider ID is used as the model ID prefix, separated from the model ID by a colon.

  • languageModel
  • embeddingModel
  • Provider
  • LanguageModel
  • EmbeddingModel

Source: createProviderRegistry. Checked 2026-10-15.