Learn how the VoyageProvider works and how to configure it
The Voyage AI provider follows the Vercel AI SDK provider pattern, giving you a consistent interface for generating embeddings and reranking documents.
A provider is a factory that creates model instances. The Voyage provider implements the ProviderV3 interface from the AI SDK, which means it integrates seamlessly with the rest of the AI SDK ecosystem.When you create a provider instance, you configure shared settings like API keys and base URLs. Then you use that provider to create individual model instances.
You can use the default provider instance or create a custom one:
import { voyage, createVoyage } from 'voyage-ai-provider';// Use the default providerconst embedding = voyage('voyage-3');// Or create a custom provider with specific settingsconst customVoyage = createVoyage({ apiKey: process.env.VOYAGE_API_KEY, baseURL: 'https://api.voyageai.com/v1',});const embedding = customVoyage('voyage-3');
The VoyageProviderSettings interface defines the configuration options:
interface VoyageProviderSettings { /** * API key for authentication. Defaults to VOYAGE_API_KEY environment variable. */ apiKey?: string; /** * Base URL for API calls. Defaults to https://api.voyageai.com/v1 * Use this to configure proxy servers. */ baseURL?: string; /** * Custom headers to include in requests. */ headers?: Record<string, string>; /** * Custom fetch implementation for middleware or testing. */ fetch?: FetchFunction;}
The provider automatically reads your API key from the VOYAGE_API_KEY environment variable if you don’t provide one explicitly.
// Using reranking methodconst reranker = voyage.reranking('rerank-2');// Using rerankingModel method (same result)const reranker = voyage.rerankingModel('rerank-2');
Both methods create the same RerankingModelV3 instance.
The provider uses factory methods to create model instances. Each model instance is configured with the provider’s shared settings (API key, base URL, headers, etc.).