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.| Variable | Description | Default |
|---|---|---|
ANTHROPIC_API_KEY | API key used for authentication via the x-api-key header | Required |
ANTHROPIC_BASE_URL | Base URL for all API requests | https://api.anthropic.com/v1 |
ANTHROPIC_VERSION | Value sent as the anthropic-version request header | 2023-06-01 |
Programmatic Configuration
CallAnthropic::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.
The
apiKey field is required unless ANTHROPIC_API_KEY is set in the environment.Configuration Options
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.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.Anthropic API version string sent as the
anthropic-version header. Defaults to 2023-06-01. Falls back to the ANTHROPIC_VERSION environment variable.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.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 throughGenerate 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:
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:
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:
Beta Features
Anthropic exposes preview APIs through theanthropic-beta header. Pass it in the headers option to opt in to any beta without waiting for a new package release.