Creates a Voyage AI provider instance with optional configuration settings. You can customize the API key, base URL, headers, and fetch implementation.
Import
import { createVoyage } from 'voyage-ai-provider';
Parameters
Configuration options for the Voyage providerAPI key for authenticating with the Voyage AI API. Defaults to the VOYAGE_API_KEY environment variable.
Base URL for API calls. Use this to configure proxy servers or custom endpoints. Defaults to https://api.voyageai.com/v1.
Custom headers to include in all requests.
Custom fetch implementation. Use this as middleware to intercept requests or provide a custom fetch for testing.
Returns
A Voyage provider instance that implements the Vercel AI SDK provider interface. The provider can be called as a function or you can use its methods to create specific model types.
Examples
Basic usage with environment variable
import { createVoyage } from 'voyage-ai-provider';
const voyage = createVoyage();
Custom API key
import { createVoyage } from 'voyage-ai-provider';
const voyage = createVoyage({
apiKey: process.env.VOYAGE_API_KEY,
});
Custom base URL with proxy
import { createVoyage } from 'voyage-ai-provider';
const voyage = createVoyage({
baseURL: 'https://my-proxy.example.com/voyage',
});
import { createVoyage } from 'voyage-ai-provider';
const voyage = createVoyage({
headers: {
'X-Custom-Header': 'value',
},
});
Custom fetch for testing
import { createVoyage } from 'voyage-ai-provider';
const voyage = createVoyage({
fetch: async (url, options) => {
console.log('Request:', url, options);
return fetch(url, options);
},
});