
# Voyage AI Provider

The [Voyage AI](https://www.voyageai.com/) provider contains embedding and reranking model support for the Voyage AI API.

## Setup

The Voyage AI provider is available in the `@ai-sdk/voyage` module. You can install it with

<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
  <Tab>
    <Snippet text="pnpm add @ai-sdk/voyage" dark />
  </Tab>
  <Tab>
    <Snippet text="npm install @ai-sdk/voyage" dark />
  </Tab>
  <Tab>
    <Snippet text="yarn add @ai-sdk/voyage" dark />
  </Tab>
  <Tab>
    <Snippet text="bun add @ai-sdk/voyage" dark />
  </Tab>
</Tabs>

## Provider Instance

You can import the default provider instance `voyage` from `@ai-sdk/voyage`:

```ts
import { voyage } from '@ai-sdk/voyage';
```

If you need a customized setup, you can import `createVoyage` from `@ai-sdk/voyage`
and create a provider instance with your settings:

```ts
import { createVoyage } from '@ai-sdk/voyage';

const voyage = createVoyage({
  // custom settings
});
```

You can use the following optional settings to customize the Voyage AI provider instance:

- **baseURL** _string_

  Use a different URL prefix for API calls, e.g. to use proxy servers.
  The default prefix is `https://api.voyageai.com/v1`.

- **apiKey** _string_

  API key that is being sent using the `Authorization` header.
  It defaults to the `VOYAGE_API_KEY` environment variable.

- **headers** _Record&lt;string,string&gt;_

  Custom headers to include in the requests.

- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise&lt;Response&gt;_

  Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
  Defaults to the global `fetch` function.
  You can use it as a middleware to intercept requests,
  or to provide a custom fetch implementation for e.g. testing.

## Embedding Models

You can create models that call the [Voyage AI embeddings API](https://docs.voyageai.com/reference/embeddings-api)
using the `.embedding()` factory method.

```ts
const model = voyage.embedding('voyage-3.5');
```

You can use Voyage AI embedding models to generate embeddings with the `embed` function:

```ts
import { voyage } from '@ai-sdk/voyage';
import { embed } from 'ai';

const { embedding } = await embed({
  model: voyage.embedding('voyage-3.5'),
  value: 'sunny day at the beach',
});
```

Voyage AI embedding models support additional provider options that can be passed via `providerOptions.voyage`:

```ts
import { voyage, type VoyageEmbeddingModelOptions } from '@ai-sdk/voyage';
import { embed } from 'ai';

const { embedding } = await embed({
  model: voyage.embedding('voyage-4-large'),
  value: 'sunny day at the beach',
  providerOptions: {
    voyage: {
      inputType: 'document',
      outputDimension: 512,
    } satisfies VoyageEmbeddingModelOptions,
  },
});
```

The following provider options are available:

- **inputType** _'query' | 'document' | null_

  Specifies the type of input passed to the model. Defaults to `null`.

  - `null`: The embedding model directly converts the inputs into numerical vectors.
  - `'query'`: Used for embeddings of search queries run against a vector DB to find relevant documents.
  - `'document'`: Used for embeddings stored in a vector database for search use-cases.

- **truncation** _boolean_

  Whether to truncate the input texts to fit within the model's context length. Defaults to `true`.

- **outputDimension** _number_

  The number of dimensions for the resulting output embeddings.
  Supported by models with flexible dimensions (e.g. `voyage-4-large`, `voyage-4`, `voyage-4-lite`, `voyage-4-nano`, `voyage-code-3.5`, `voyage-code-3`, `voyage-3-large`, `voyage-3.5`, `voyage-3.5-lite`).
  Supported values: 256, 512, 1024, 2048.

- **outputDtype** _'float' | 'int8' | 'uint8' | 'binary' | 'ubinary'_

  The data type for the output embeddings. Defaults to `'float'`.

  - `'float'`: 32-bit floating-point numbers.
  - `'int8'`, `'uint8'`: 8-bit integer types.
  - `'binary'`, `'ubinary'`: Bit-packed, quantized single-bit embedding values.

### Model Capabilities

| Model                   | Default Dimensions | Context Length |
| ----------------------- | ------------------ | -------------- |
| `voyage-4-large`        | 1024               | 32,000         |
| `voyage-4`              | 1024               | 32,000         |
| `voyage-4-lite`         | 1024               | 32,000         |
| `voyage-4-nano`         | 1024               | 32,000         |
| `voyage-code-3.5`       | 1024               | 32,000         |
| `voyage-code-3`         | 1024               | 32,000         |
| `voyage-3-large`        | 1024               | 32,000         |
| `voyage-3.5`            | 1024               | 32,000         |
| `voyage-3.5-lite`       | 1024               | 32,000         |
| `voyage-3`              | 1024               | 32,000         |
| `voyage-3-lite`         | 512                | 32,000         |
| `voyage-finance-2`      | 1024               | 32,000         |
| `voyage-multilingual-2` | 1024               | 32,000         |
| `voyage-law-2`          | 1024               | 16,000         |
| `voyage-code-2`         | 1536               | 16,000         |

<Note>
  The table above lists popular models. Please see the [Voyage AI
  docs](https://docs.voyageai.com/docs/embeddings) for a full list of available
  models. You can also pass any available provider model ID as a string if
  needed.
</Note>

## Reranking Models

You can create models that call the [Voyage AI rerank API](https://docs.voyageai.com/reference/rerank-api)
using the `.reranking()` factory method.

```ts
const model = voyage.reranking('rerank-2.5');
```

You can use Voyage AI reranking models to rerank documents with the `rerank` function:

```ts
import { voyage } from '@ai-sdk/voyage';
import { rerank } from 'ai';

const documents = [
  'sunny day at the beach',
  'rainy afternoon in the city',
  'snowy night in the mountains',
];

const { ranking } = await rerank({
  model: voyage.reranking('rerank-2.5'),
  documents,
  query: 'talk about rain',
  topN: 2,
});

console.log(ranking);
```

Voyage AI reranking models support additional provider options that can be passed via `providerOptions.voyage`:

```ts
import { voyage, type VoyageRerankingModelOptions } from '@ai-sdk/voyage';
import { rerank } from 'ai';

const { ranking } = await rerank({
  model: voyage.reranking('rerank-2.5'),
  documents: ['sunny day at the beach', 'rainy afternoon in the city'],
  query: 'talk about rain',
  providerOptions: {
    voyage: {
      returnDocuments: true,
      truncation: true,
    } satisfies VoyageRerankingModelOptions,
  },
});
```

The following provider options are available:

- **returnDocuments** _boolean_

  Whether to return the documents in the response. Defaults to `false`.

- **truncation** _boolean_

  Whether to truncate the input texts to fit within the model's context length. Defaults to `true`.

### Model Capabilities

| Model              | Context Length |
| ------------------ | -------------- |
| `rerank-2.5`       | 32,000         |
| `rerank-2.5-lite`  | 32,000         |
| `rerank-2`         | 16,000         |
| `rerank-2-lite`    | 8,000          |
| `rerank-1`         | 8,000          |
| `rerank-lite-1`    | 4,000          |


## Navigation

- [AI Gateway](/providers/ai-sdk-providers/ai-gateway)
- [xAI Grok](/providers/ai-sdk-providers/xai)
- [Vercel](/providers/ai-sdk-providers/vercel)
- [OpenAI](/providers/ai-sdk-providers/openai)
- [Azure OpenAI](/providers/ai-sdk-providers/azure)
- [Anthropic](/providers/ai-sdk-providers/anthropic)
- [Open Responses](/providers/ai-sdk-providers/open-responses)
- [Amazon Bedrock](/providers/ai-sdk-providers/amazon-bedrock)
- [Groq](/providers/ai-sdk-providers/groq)
- [Fal](/providers/ai-sdk-providers/fal)
- [AssemblyAI](/providers/ai-sdk-providers/assemblyai)
- [DeepInfra](/providers/ai-sdk-providers/deepinfra)
- [Deepgram](/providers/ai-sdk-providers/deepgram)
- [Black Forest Labs](/providers/ai-sdk-providers/black-forest-labs)
- [Gladia](/providers/ai-sdk-providers/gladia)
- [LMNT](/providers/ai-sdk-providers/lmnt)
- [Google Generative AI](/providers/ai-sdk-providers/google-generative-ai)
- [Hume](/providers/ai-sdk-providers/hume)
- [Google Vertex AI](/providers/ai-sdk-providers/google-vertex)
- [Rev.ai](/providers/ai-sdk-providers/revai)
- [Baseten](/providers/ai-sdk-providers/baseten)
- [Hugging Face](/providers/ai-sdk-providers/huggingface)
- [Mistral AI](/providers/ai-sdk-providers/mistral)
- [Together.ai](/providers/ai-sdk-providers/togetherai)
- [Cohere](/providers/ai-sdk-providers/cohere)
- [Fireworks](/providers/ai-sdk-providers/fireworks)
- [Voyage AI](/providers/ai-sdk-providers/voyage)
- [DeepSeek](/providers/ai-sdk-providers/deepseek)
- [Moonshot AI](/providers/ai-sdk-providers/moonshotai)
- [Alibaba](/providers/ai-sdk-providers/alibaba)
- [Cerebras](/providers/ai-sdk-providers/cerebras)
- [Replicate](/providers/ai-sdk-providers/replicate)
- [Prodia](/providers/ai-sdk-providers/prodia)
- [Perplexity](/providers/ai-sdk-providers/perplexity)
- [Luma](/providers/ai-sdk-providers/luma)
- [ByteDance](/providers/ai-sdk-providers/bytedance)
- [Kling AI](/providers/ai-sdk-providers/klingai)
- [ElevenLabs](/providers/ai-sdk-providers/elevenlabs)


[Full Sitemap](/sitemap.md)
