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.

aisdk/anthropic supports two configuration approaches that can be combined freely. The simplest is environment variables: export one or more of the variables listed below and the provider picks them up automatically when Anthropic::model() is first called. For finer-grained control — or when you need multiple provider instances with different credentials — use Anthropic::create() to pass a configuration array programmatically.

Environment Variables

Environment variables are the recommended approach for production deployments because they keep credentials out of source code. Each variable has a corresponding programmatic option; if both are set, the programmatic value takes precedence.
VariableDescriptionDefault
ANTHROPIC_API_KEYAPI key used for authentication via the x-api-key headerRequired
ANTHROPIC_BASE_URLBase URL for all API requestshttps://api.anthropic.com/v1
ANTHROPIC_VERSIONValue sent as the anthropic-version request header2023-06-01

Programmatic Configuration

Call Anthropic::create() with an options array to configure the provider in code. This also sets the provider as the package-wide default, so subsequent calls to Anthropic::model() use the instance you created.
use AiSdk\Anthropic;

$provider = Anthropic::create([
    'apiKey'  => 'sk-ant-...',
    'baseUrl' => 'https://api.anthropic.com/v1',
    'version' => '2023-06-01',
    'headers' => ['anthropic-beta' => 'extended-thinking-2025-05-14'],
]);
The apiKey field is required unless ANTHROPIC_API_KEY is set in the environment.

Configuration Options

apiKey
string
required
Your Anthropic API key. Sent as the x-api-key header on every request. Falls back to the ANTHROPIC_API_KEY environment variable when omitted.
baseUrl
string
Base URL for all API requests. Trailing slashes are stripped automatically. Defaults to https://api.anthropic.com/v1. Falls back to the ANTHROPIC_BASE_URL environment variable.
version
string
Anthropic API version string sent as the anthropic-version header. Defaults to 2023-06-01. Falls back to the ANTHROPIC_VERSION environment variable.
headers
array
An associative array of additional HTTP headers merged into every request. Use this to pass beta feature flags such as anthropic-beta, or any other custom header the API accepts. Defaults to an empty array.
sdk
Sdk|null
A custom Sdk instance that wraps a PSR-18 HTTP client, a PSR-17 request factory, and a PSR-17 stream factory. Useful for injecting a test double or a pre-configured HTTP client in your application. Defaults to null, which causes the provider to use auto-discovery.

SDK-Level Helpers

The core SDK exposes two helper methods for managing the default model and provider state at runtime. These are available through Generate from aisdk/core. Generate::configure() lets you set or replace the default text model for all subsequent Generate::text() calls without calling Generate::model() on each one:
use AiSdk\Anthropic;
use AiSdk\Generate;

Generate::configure(Anthropic::model('claude-sonnet-4'));
Generate::reset() clears the default model configured via Generate::model() or Generate::configure(), returning the Generate facade to its unconfigured state. This is useful in tests or when switching providers at runtime:
use AiSdk\Generate;

Generate::reset();
Anthropic::reset() clears the cached default AnthropicProvider instance created by Anthropic::create(). After calling it, the next call to Anthropic::model() will recreate the provider from environment variables:
use AiSdk\Anthropic;

Anthropic::reset();

Beta Features

Anthropic exposes preview APIs through the anthropic-beta header. Pass it in the headers option to opt in to any beta without waiting for a new package release.
use AiSdk\Anthropic;

$provider = Anthropic::create([
    'apiKey'  => 'sk-ant-...',
    'headers' => [
        'anthropic-beta' => 'extended-thinking-2025-05-14',
    ],
]);
You can register a new Claude model — one not yet listed in the package’s model catalog — alongside a beta header so both reach the API together. See the Custom Model Registration section of the README for details.

Build docs developers (and LLMs) love