Skip to main content

Documentation Index

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

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

There are two ways to configure the ElevenLabs provider: through environment variables, which require no PHP code at all, or through an explicit configuration array passed to ElevenLabs::create(). Both approaches produce an ElevenLabsProvider instance backed by an ElevenLabsOptions value object that carries the resolved settings for the lifetime of that provider.

Environment Variable Configuration

The simplest path is to set ELEVENLABS_API_KEY in your environment. The provider reads it automatically the first time any static method is called on the ElevenLabs facade:
export ELEVENLABS_API_KEY=xi-...
use AiSdk\ElevenLabs;

// No ElevenLabs::create() call needed — the provider is lazily
// initialized from ELEVENLABS_API_KEY the first time it is used.
$model = ElevenLabs::model('eleven_flash_v2_5');
You can also override the default base URL through the environment without touching your PHP code:
export ELEVENLABS_API_KEY=xi-...
export ELEVENLABS_BASE_URL=https://your-proxy.example.com/elevenlabs/v1
ELEVENLABS_BASE_URL takes effect only when no baseUrl key is provided in the configuration array. An explicit baseUrl passed to ElevenLabs::create() always takes precedence.

Explicit Configuration

Call ElevenLabs::create() with a configuration array to supply options directly in PHP. This is the right approach when you are managing secrets through a vault, a DI container, or when you need to configure multiple providers with different keys:
use AiSdk\ElevenLabs;

$provider = ElevenLabs::create([
    'apiKey'  => 'xi-...',
    'baseUrl' => 'https://api.elevenlabs.io/v1',
    'headers' => ['X-Custom-Header' => 'value'],
]);
ElevenLabs::create() returns the new ElevenLabsProvider instance and simultaneously registers it as the static default, so subsequent calls to the ElevenLabs:: facade methods will use this configuration.

Configuration Keys

apiKey
string
required
Your ElevenLabs API key. If omitted, the provider falls back to the ELEVENLABS_API_KEY environment variable. An exception is thrown at provider construction time if neither source supplies a value.
baseUrl
string
The base URL for all API requests. Defaults to https://api.elevenlabs.io/v1. Trailing slashes are stripped automatically. If omitted, the provider checks ELEVENLABS_BASE_URL before using the default. Useful for routing requests through a proxy or a local mock server during testing.
headers
array<string, string>
A key-value map of additional HTTP headers to include on every request. These are merged with the authentication header. Any key present in headers will override a header of the same name that the provider would otherwise set, with the exception that xi-api-key is always set from apiKey first and your custom headers are applied on top.

How Authentication Headers Are Built

Every outbound request carries the headers produced by ElevenLabsOptions::authHeaders(). The method sets xi-api-key to your resolved API key and then merges your custom headers array on top using array_replace, so custom headers always win on key conflicts:
/** @return array<string, string> */
public function authHeaders(): array
{
    return array_replace(['xi-api-key' => $this->apiKey], $this->headers);
}
For a typical request the outgoing headers look like:
[
    'xi-api-key' => 'xi-...',
    // plus any entries from your 'headers' config key
]

Using a Proxy or Custom Endpoint

To route all ElevenLabs traffic through a proxy or a staging endpoint, set baseUrl explicitly:
use AiSdk\ElevenLabs;

ElevenLabs::create([
    'apiKey'  => 'xi-...',
    'baseUrl' => 'https://your-proxy.example.com/elevenlabs/v1',
]);
Or, to keep it out of your PHP code entirely:
export ELEVENLABS_BASE_URL=https://your-proxy.example.com/elevenlabs/v1

Resetting the Static Facade

ElevenLabs::reset() clears the static default provider, forcing the next call to the facade to construct a fresh instance. This is primarily useful in tests where you want to ensure configuration changes are fully isolated between test cases:
use AiSdk\ElevenLabs;

beforeEach(function () {
    ElevenLabs::reset();
});

it('uses the configured API key', function () {
    ElevenLabs::create(['apiKey' => 'xi-test-key']);

    // ElevenLabs::model() now resolves against the test provider
    $model = ElevenLabs::model('eleven_flash_v2_5');

    expect($model->id())->toBe('eleven_flash_v2_5');
});
ElevenLabs::reset() only affects the static facade. ElevenLabsProvider instances you hold directly are unaffected.

Configuration Reference

SourceKey / VariablePriority
ElevenLabs::create() arrayapiKeyHighest
Environment variableELEVENLABS_API_KEYFallback for apiKey
ElevenLabs::create() arraybaseUrlHighest
Environment variableELEVENLABS_BASE_URLFallback for baseUrl
Built-in defaulthttps://api.elevenlabs.io/v1Lowest

Build docs developers (and LLMs) love