Skip to main content

Documentation Index

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

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

AnthropicOptions is a final, immutable value object holding all configuration for the Anthropic provider. Every public property is declared readonly, so the object cannot be mutated after construction. Create one via the fromArray() static factory — which handles environment variable fallbacks — or directly via the constructor when you have all values at hand.

Constants

DEFAULT_BASE_URL
string
'https://api.anthropic.com/v1' — The default base URL used for all API requests when no override is provided.
DEFAULT_VERSION
string
'2023-06-01' — The default value sent as the anthropic-version request header.
PROVIDER_NAME
string
'anthropic' — The canonical provider name string returned by AnthropicProvider::name() and used to scope model registry entries.

Constructor Parameters

__construct(
    string $apiKey,
    string $baseUrl = self::DEFAULT_BASE_URL,
    string $version = self::DEFAULT_VERSION,
    array  $headers = [],
    ?Sdk   $sdk = null,
)
All parameters map directly to readonly public properties of the same name.
apiKey
string
required
Your Anthropic API key. Sent as the x-api-key HTTP header on every request. Must be a non-empty string — the SDK throws if it is missing and the ANTHROPIC_API_KEY environment variable is also absent.
baseUrl
string
default:"https://api.anthropic.com/v1"
Base URL for API requests. Any trailing slash is stripped automatically by fromArray(). Override this when pointing at a proxy, a local mock server, or a compatible third-party endpoint.
version
string
default:"2023-06-01"
Anthropic API version string. Sent as the anthropic-version header on every request. Change this only if Anthropic instructs you to use a different version.
headers
array
default:"[]"
Additional HTTP headers merged into every request after the authentication headers. Useful for Anthropic beta feature flags such as 'anthropic-beta' => 'extended-thinking-2025-05-14'. Custom headers are merged last, so they can override the default auth headers if keys collide.
sdk
Sdk|null
default:"null"
Optional Sdk instance wrapping a PSR-18 HTTP client, PSR-17 request factory, and PSR-17 stream factory. Inject a custom Sdk to control transport behaviour — for example to supply a mock HTTP client in tests or to configure timeouts and middleware.

fromArray()

static fromArray(array $config = []): self
The recommended way to construct an AnthropicOptions instance. Reads apiKey, baseUrl, version, headers, and sdk from the supplied array, falling back to environment variables for the first three when the corresponding key is absent or null.
Array keyEnvironment variable fallbackDefault value
apiKeyANTHROPIC_API_KEY(required)
baseUrlANTHROPIC_BASE_URLhttps://api.anthropic.com/v1
versionANTHROPIC_VERSION2023-06-01
headers[]
sdknull
$options = AnthropicOptions::fromArray([
    'apiKey'  => 'sk-ant-...',
    'baseUrl' => 'https://api.anthropic.com/v1',
    'version' => '2023-06-01',
    'headers' => ['anthropic-beta' => 'extended-thinking-2025-05-14'],
]);
When apiKey is omitted from the array and ANTHROPIC_API_KEY is not set in the environment, fromArray() throws an exception. Always ensure at least one of these is present before creating a provider.

authHeaders()

authHeaders(): array<string, string>
Returns the complete set of authentication and version headers to attach to every API request. Merges the fixed authentication headers with any additional headers supplied at construction time. The result is passed directly to the HTTP layer by AnthropicTextModel.
// Equivalent to:
[
    'x-api-key'         => $this->apiKey,
    'anthropic-version' => $this->version,
    // ...plus any entries from $this->headers
]
You do not need to call authHeaders() yourself — AnthropicTextModel calls it internally before every generate() and stream() request. It is exposed as a public method to facilitate testing and custom transport layers.

Build docs developers (and LLMs) love