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.

The VoyageAI facade resolves its configuration in a layered way: values passed to VoyageAI::create() take precedence, and any option left unset falls back to the corresponding environment variable. This means you can run the same application code in development (with an .env file) and in production (with real secrets injected by your platform) without changing a line of PHP.

Environment Variables

These variables are read automatically when the provider is initialised. Neither needs to be present if you supply the equivalent option to VoyageAI::create().
VariableRequiredDefaultDescription
VOYAGE_API_KEYYesAPI key used to authenticate every request via the Authorization: Bearer header.
VOYAGE_BASE_URLNohttps://api.voyageai.com/v1Base URL for all API requests. Override this to point at a proxy or a self-hosted compatible endpoint.
Store VOYAGE_API_KEY in your platform’s secret manager or CI/CD environment rather than in source control. The environment variable approach means the key never has to appear in your PHP files.

Programmatic Configuration

Call VoyageAI::create() once at application bootstrap to configure the default provider instance. Every subsequent call to VoyageAI::model() reuses that instance automatically. You can retrieve the current default provider directly with VoyageAI::default(), which lazily calls create() with an empty config if none has been set — meaning VOYAGE_API_KEY must be present in the environment when using lazy initialisation.
<?php

declare(strict_types=1);

use AiSdk\VoyageAI;

VoyageAI::create([
    'apiKey'  => 'pa-...',
    'baseUrl' => 'https://api.voyageai.com/v1',
    'headers' => [
        'X-Custom-Header' => 'my-value',
    ],
]);

Options

apiKey
string
required
Your Voyage AI API key. When omitted, the value of the VOYAGE_API_KEY environment variable is used. An InvalidArgumentException is thrown at construction time if neither is present.
baseUrl
string
default:"https://api.voyageai.com/v1"
Base URL for all API requests. Trailing slashes are stripped automatically. Reads from VOYAGE_BASE_URL when not provided inline.
headers
array<string, string>
default:"[]"
Additional HTTP headers merged into every outgoing request alongside the Authorization header. Useful for passing proxy tokens, request-tracing headers, or any other custom metadata your infrastructure requires.

Custom Headers

Headers are merged on top of the default Authorization: Bearer <apiKey> header, so you can add as many extra headers as needed without losing authentication:
<?php

declare(strict_types=1);

use AiSdk\VoyageAI;

VoyageAI::create([
    'apiKey' => 'pa-...',
    'headers' => [
        'X-Request-ID'    => 'my-trace-id-123',
        'X-Custom-Source' => 'my-app',
    ],
]);

Provider Reset

VoyageAI::reset() clears the stored default provider instance, causing the next VoyageAI::model() call to re-initialise from scratch. This is particularly useful in test suites where each test should start from a clean slate:
<?php

declare(strict_types=1);

use AiSdk\Generate;
use AiSdk\VoyageAI;

afterEach(function () {
    Generate::reset();
    VoyageAI::reset();
});
Calling VoyageAI::reset() in production between requests will discard the configured provider and cause the next call to re-read environment variables, rebuilding the instance. Only use reset() in test contexts or when you intentionally need to swap credentials at runtime.

Build docs developers (and LLMs) love