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.
You can attach a provider's files or skills interface to your custom provider. This allows you to use uploadFile and uploadSkill through the same provider abstraction.
import { anthropic } from '@ai-sdk/anthropic';import { openai } from '@ai-sdk/openai';import { createProviderRegistry, gateway } from 'ai';export const registry = createProviderRegistry({ // register provider with prefix and default setup using gateway: gateway, // register provider with prefix and direct provider import: anthropic, openai,});
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-6-astra'), // default separator // or with custom separator: // model: customSeparatorRegistry.languageModel('openai > gpt-6-astra'), prompt: 'Invent a new holiday and describe its traditions.',});
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',});
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',});
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 { experimental_generateVideo } from 'ai';import { fal } from '@ai-sdk/fal';import { createProviderRegistry } 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',});
You can access a provider's files interface by calling registry.files(providerId).
This is useful when you want to upload files through a provider in the registry before referencing them in model requests.
import { openai } from '@ai-sdk/openai';import { createProviderRegistry, customProvider, generateText, uploadFile,} from 'ai';const registry = createProviderRegistry({ openai: customProvider({ languageModels: { 'gpt-6-luna': openai.responses('gpt-6-luna') }, files: openai.files(), }),});const { providerReference } = await uploadFile({ api: registry.files('openai'), data: fileData, filename: 'image.png',});const { text } = await generateText({ model: registry.languageModel('openai:gpt-6-luna'), messages: [ { role: 'user', content: [ { type: 'text', text: 'Describe what you see in this image.' }, { type: 'file', mediaType: 'image', data: providerReference }, ], }, ],});
The central idea of provider management is to set up a file that contains all the providers and models you want to use.
You may want to pre-configure model settings, provide model name aliases, limit the available models, and more.
Here is an example that implements the following concepts:
pass through gateway with a namespace prefix (here: gateway > *)
pass through a full provider with a namespace prefix (here: xai > *)
setup an OpenAI-compatible provider with custom api key and base URL (here: custom > *)
setup model name aliases (here: anthropic > fast, anthropic > writing, anthropic > reasoning)
pre-configure model settings (here: anthropic > reasoning)
validate the provider-specific options (here: AnthropicLanguageModelOptions)
use a fallback provider (here: anthropic > *)
limit a provider to certain models without a fallback (here: groq > llama-3.1-8b-instant, groq > qwen/qwen3.6-27b)
define a custom separator for the provider registry (here: >)
import { anthropic, AnthropicLanguageModelOptions } from '@ai-sdk/anthropic';import { createOpenAICompatible } from '@ai-sdk/openai-compatible';import { xai } from '@ai-sdk/xai';import { groq } from '@ai-sdk/groq';import { createProviderRegistry, customProvider, defaultSettingsMiddleware, gateway, wrapLanguageModel,} from 'ai';export const registry = createProviderRegistry( { // pass through gateway with a namespace prefix gateway, // pass through full providers with namespace prefixes xai, // access an OpenAI-compatible provider with custom setup custom: createOpenAICompatible({ name: 'provider-name', apiKey: process.env.CUSTOM_API_KEY, baseURL: 'https://api.custom.com/v1', }), // setup model name aliases anthropic: customProvider({ languageModels: { fast: anthropic('claude-haiku-5-5'), // simple model writing: anthropic('claude-sonnet-4-5'), // extended reasoning model configuration: reasoning: wrapLanguageModel({ model: anthropic('claude-sonnet-4-5'), middleware: defaultSettingsMiddleware({ settings: { maxOutputTokens: 100000, // example default setting providerOptions: { anthropic: { thinking: { type: 'enabled', budgetTokens: 32000, }, } satisfies AnthropicLanguageModelOptions, }, }, }), }), }, fallbackProvider: anthropic, }), // limit a provider to certain models without a fallback groq: customProvider({ languageModels: { 'llama-3.1-8b-instant': groq('llama-3.1-8b-instant'), 'qwen/qwen3.6-27b': groq('qwen/qwen3.6-27b'), }, }), }, { separator: ' > ' },);// usage:const model = registry.languageModel('anthropic > reasoning');
The AI SDK 5 includes a global provider feature that allows you to specify a model using just a plain model ID string:
import { streamText } from 'ai';
const result = await streamText({
model: "anthropic/claude-sonnet-5.5", // Uses the global provider (defaults to gateway)
prompt: 'Invent a new holiday and describe its traditions.',
});
By default, the global provider is set to the Vercel AI Gateway.
import { openai } from '@ai-sdk/openai';// Initialize once during startup:globalThis.AI_SDK_DEFAULT_PROVIDER = openai;
app.ts
import { streamText } from 'ai';const result = await streamText({ model: 'gpt-6-astra', // Uses OpenAI provider without prefix prompt: 'Invent a new holiday and describe its traditions.',});
This simplifies provider usage and makes it easier to switch between providers without changing your model references throughout your codebase.
Custom providers accept decisionModels aliases, and registries expose
decisionModel('provider:model'). These methods return model instances for
experimental_decide. Direct string IDs use Gateway by default, or an
explicitly configured default provider with a decisionModel method. Registry
middleware for language and image models does not apply to decision.
See Decisions
for aliases, default-provider configuration, and capability differences.