Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/phpaisdk/voyageai/llms.txt

Use this file to discover all available pages before exploring further.

VoyageAIProvider is the central provider class for the aisdk/voyageai package. It sits at the intersection of the PHP AI SDK’s provider contract and the Voyage AI API — accepting a VoyageAIOptions configuration object, advertising its name to the SDK dispatcher, and producing VoyageAIEmbeddingModel instances on demand. You will rarely need to instantiate it directly; the VoyageAI facade handles that for you. However, understanding the class is useful when you want to compose the SDK manually, inject it into a DI container, or write unit tests that work at the provider level.

Class Declaration

namespace AiSdk\VoyageAI;

use AiSdk\Contracts\BaseProvider;
use AiSdk\Contracts\EmbeddingProviderInterface;

final class VoyageAIProvider extends BaseProvider implements EmbeddingProviderInterface
{
    public function __construct(public readonly VoyageAIOptions $options) {}

    public function name(): string {}

    protected function embeddingModel(string $modelId): EmbeddingModelInterface {}
}
VoyageAIProvider extends BaseProvider (from aisdk/core) and implements EmbeddingProviderInterface. The BaseProvider base class exposes the public model(string $modelId): Model method that routes model-ID resolution to the correct protected method — embeddingModel() in this case.
Because VoyageAIProvider only implements EmbeddingProviderInterface and not a chat or completion provider interface, calling model() with a non-embedding model ID will delegate to the base class, which will throw unless the base class has a suitable handler. Voyage AI exclusively offers embedding models.

Constructor

public function __construct(public readonly VoyageAIOptions $options)
The constructor accepts a single VoyageAIOptions instance and promotes it to a public readonly property. Once constructed, the options (API key, base URL, headers, and optional HTTP client) cannot be changed — create a new provider to use different settings.
options
VoyageAIOptions
required
A fully-configured VoyageAIOptions object. Use VoyageAIOptions::fromArray() for the most ergonomic construction, or instantiate it directly when you need precise control over every field.

Methods

name(): string

Returns the canonical provider name string used internally by the PHP AI SDK to identify this provider in metadata, error messages, and provider-scoped options. Returns 'voyageai' (the value of VoyageAIOptions::PROVIDER_NAME).
$provider = new VoyageAIProvider(VoyageAIOptions::fromArray(['apiKey' => 'pa-...']));

echo $provider->name(); // 'voyageai'

model(string $modelId): Model (inherited from BaseProvider)

Resolves a model identifier to a concrete VoyageAIEmbeddingModel instance. This method is defined on BaseProvider and delegates to the protected embeddingModel() implementation in VoyageAIProvider.
modelId
string
required
Any Voyage AI embedding model identifier, e.g. 'voyage-4-large', 'voyage-3-lite', 'voyage-code-3'. The SDK accepts any non-empty string and does not validate against a fixed list, allowing forward compatibility with new models.
Returns AiSdk\Contracts\Model — a VoyageAIEmbeddingModel bound to $modelId and the provider’s VoyageAIOptions.

Direct Instantiation

While the VoyageAI facade is the recommended entry point, you can instantiate VoyageAIProvider directly when you need explicit control — for example, in a service container binding or a custom bootstrapping class.
use AiSdk\VoyageAI\VoyageAIOptions;
use AiSdk\VoyageAI\VoyageAIProvider;

$provider = new VoyageAIProvider(
    VoyageAIOptions::fromArray(['apiKey' => 'pa-...'])
);

$model = $provider->model('voyage-4-large');
You can also wire the provider into a DI container and inject it wherever needed:
// In a service provider / container binding
$container->singleton(VoyageAIProvider::class, function () {
    return new VoyageAIProvider(
        VoyageAIOptions::fromArray(['apiKey' => env('VOYAGE_API_KEY')])
    );
});

// In a class that needs embeddings
class DocumentIndexer
{
    public function __construct(private readonly VoyageAIProvider $provider) {}

    public function index(string $text): array
    {
        $model = $this->provider->model('voyage-4-large');
        // ... use with Generate::embedding() ...
    }
}

EmbeddingProviderInterface

VoyageAIProvider implements EmbeddingProviderInterface from aisdk/core. This interface signals to the SDK that the provider can produce embedding models and that provider-scoped options sent under the 'voyageai' key (via ->providerOptions('voyageai', [...])) will be forwarded to the underlying HTTP request.

Supported

Text embedding generation via Generate::embedding()

Not Supported

Chat completions, image generation, or other non-embedding modalities
use AiSdk\Generate;
use AiSdk\VoyageAI\VoyageAIOptions;
use AiSdk\VoyageAI\VoyageAIProvider;

$provider = new VoyageAIProvider(
    VoyageAIOptions::fromArray(['apiKey' => 'pa-...'])
);

$result = Generate::embedding(['Doc one', 'Doc two'])
    ->model($provider->model('voyage-4-large'))
    ->dimensions(512)
    ->providerOptions('voyageai', ['input_type' => 'document'])
    ->run();

Build docs developers (and LLMs) love