[Voyage AI](/ai-gateway/models/labs/voyage)

# Voyage Code 2

Voyage Code 2 is Voyage AI's code-specialized embedding model with a context window of 0 tokens. It improves code retrieval by 14.52% over OpenAI text-embedding-3-large and supports Python, C++, Java, and major ML framework documentation. Your use is subject to Voyage AI's [Terms](https://www.voyageai.com/tos) & [Privacy](https://www.voyageai.com/privacy) Policies.

[Use with AI Gateway](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Futm_source%3Dgateway-model-page%26utm_campaign%3Dai-gateway-models&title=Get+Started+with+Vercel+AI+Gateway) [View docs](https://vercel.com/docs/ai-gateway)

```
1import { embed } from 'ai';
2

3const result = await embed({
4  model: 'voyage/voyage-code-2',
5  value: 'Sunny day at the beach',
6})
```

[Read docs](https://vercel.com/docs/ai-gateway/sdks-and-apis/ai-sdk)

[Overview](/ai-gateway/models/voyage-code-2) [About](/ai-gateway/models/voyage-code-2/about) [Providers](/ai-gateway/models/voyage-code-2/providers) [Similar](/ai-gateway/models/voyage-code-2/similar) [FAQ](/ai-gateway/models/voyage-code-2/faq)

## [Copy link to heading](#providers)Providers

Route requests across multiple providers. Copy a provider slug to set your preference. Visit the [docs](/docs/ai-gateway/provider-options) for more info. Using a provider means you agree to their terms, listed under Legal.

| Provider |
| --- |

| Context | Input | Capabilities | ZDR | No Training | Free Tier | Release Date |  |
| --- | --- | --- | --- | --- | --- | --- | --- |

| ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) [Voyage AI](/ai-gateway/models/providers/voyage) Legal:[Terms](https://www.voyageai.com/tos)•[Privacy](https://www.voyageai.com/privacy) |  | $0.12/M |  |  |  |  | 01/01/2024 |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |

## [Copy link to heading](#more-models-by-voyage-ai)More models by Voyage AI

All

Embed

Rerank

| Model |
| --- |

| Context | Latency | Throughput | Input | Output | Cache | Web Search | Capabilities | Providers | ZDR | No Training | Free Tier | Release Date |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |

| ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) [voyage/voyage\-4-large](/ai-gateway/models/voyage-4-large) | 32K |  |  | $0.12/M |  |  | — |  | ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) |  |  |  | 01/15/2026 |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) [voyage/voyage-4](/ai-gateway/models/voyage-4) | 32K |  |  | $0.06/M |  |  | — |  | ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) |  |  |  | 01/15/2026 |  |
| ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) [voyage/voyage-4-lite](/ai-gateway/models/voyage-4-lite) | 32K |  |  | $0.02/M |  |  | — |  | ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) |  |  |  | 01/15/2026 |  |
| ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) [voyage/rerank-2.5](/ai-gateway/models/rerank-2.5) | 32K |  |  | $0.05/M |  |  | — |  | ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) |  |  |  | 08/11/2025 |  |
| ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) [voyage/rerank-2.5-lite](/ai-gateway/models/rerank-2.5-lite) | 32K |  |  | $0.02/M |  |  | — |  | ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) |  |  |  | 08/11/2025 |  |
| ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) [voyage/voyage-3.5-lite](/ai-gateway/models/voyage-3.5-lite) |  |  |  | $0.02/M |  |  | — |  | ![voyage logo](/vc-ap-vercel-marketing/_next/image?url=https%3A%2F%2F7nyt0uhk7sse4zvn.public.blob.vercel-storage.com%2Fdocs-assets%2Fstatic%2Fdocs%2Fai-gateway%2Flogos%2Fvoyage.png&w=48&q=75) |  |  |  | 05/20/2025 |  |

## [Copy link to heading](#about-voyage-code-2)About Voyage Code 2

Voyage Code 2 is Voyage AI's code-specialized embedding model, released January 1, 2024. It features a context window of 0 tokens and targets code retrieval, code completion, and code assistant applications. On code retrieval tasks across 11 datasets derived from HumanEval, APPS, MBPP, DS-1000, CodeChef, and LeetCode, Voyage Code 2 achieves a 14.52% improvement in recall@5 over OpenAI text-embedding-3-large.

Voyage Code 2 also performs well on general-purpose text retrieval, exceeding OpenAI text-embedding-3-large by 3.03% and Cohere Embed v3 by 4.93%. You can use a single embedding model for both code and documentation retrieval rather than maintaining separate indices with different models.

Voyage AI evaluates it on Python, C++, and Java, plus documentation and usage patterns for Matplotlib, NumPy, Pandas, PyTorch, SciPy, scikit-learn, and TensorFlow. The model handles both natural language queries searching for code (text-to-code) and code snippets searching for similar code (code-to-code).

## [Copy link to heading](#what-to-consider-when-choosing-a-provider)What To Consider When Choosing a Provider

- Configuration: Voyage Code 2 targets code search. If you're embedding source code, function signatures, and documentation for retrieval, it outperforms general-purpose embedding models by a wide margin.
- Configuration: Voyage AI released voyage-code-3, which supports 300+ programming languages, a 32K context window, and Matryoshka dimensionality. Use voyage-code-3 for new deployments unless you need compatibility with existing Voyage Code 2 indices.
- Configuration: Despite its code focus, Voyage Code 2 outperforms several general-purpose models on standard text retrieval. Use it for mixed code-and-documentation corpora without a second model.
- Zero Data Retention: Zero Data Retention is offered on a per-provider and model basis. See the [documentation](https://vercel.com/docs/ai-gateway/security-and-compliance/zdr) for details.
- Authentication: AI Gateway authenticates requests using an [API key](https://vercel.com/docs/ai-gateway/authentication-and-byok#api-key-authentication) or [OIDC token](https://vercel.com/docs/ai-gateway/authentication-and-byok#oidc-token-authentication). You do not need to manage provider credentials directly.

## [Copy link to heading](#when-to-use-voyage-code-2)When to Use Voyage Code 2

### Best for

- Code search engines: Retrieve relevant functions, classes, or modules from natural language queries
- Code completion pipelines: Retrieval-augmented generation finds similar code patterns
- Developer documentation search: API references, library docs, and code examples
- Mixed code and text retrieval: A single model handles both source code and natural language documentation
- ML framework documentation: Retrieval for Python-centric data science and machine learning workflows

### Consider alternatives when

- You need broader language coverage: Voyage-code-3 supports 300+ programming languages beyond Python, C++, and Java
- You need a longer context window: Voyage-code-3 offers 32K tokens versus Voyage Code 2's 0 tokens
- Your workload is general-purpose text with no code: A general-purpose embedding model like voyage-3.5 fits better
- You need Matryoshka dimensionality: Voyage-code-3 supports 2048/1024/512/256 dimensions for flexible sizing

## [Copy link to heading](#conclusion)Conclusion

Voyage Code 2 delivers a 14.52% code retrieval improvement over OpenAI text-embedding-3-large. If you have existing Voyage Code 2 indices, you can keep them and avoid a re-embed. For new deployments, use voyage-code-3 for its broader language coverage, longer context window, and Matryoshka dimensionality. Route requests through AI Gateway for unified access.