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.

AnthropicProvider is a final class that extends BaseProvider. It holds an AnthropicOptions configuration object as a public readonly property and creates AnthropicTextModel instances on demand. Because the class is final it cannot be subclassed. You typically interact with it via the Anthropic facade rather than directly — but constructing a provider manually is useful when you need multiple configured providers in the same process, or when wiring up a dependency injection container.

Constructor

__construct(public readonly AnthropicOptions $options)
Creates a new provider bound to the supplied options object. The $options parameter is promoted to a public readonly property, so it is accessible as $provider->options after construction. All subsequent model handles created by this provider share the same configuration.
options
AnthropicOptions
required
The fully constructed configuration object. Use AnthropicOptions::fromArray() to build one from a plain associative array.
use AiSdk\Anthropic\AnthropicOptions;
use AiSdk\Anthropic\AnthropicProvider;

$provider = new AnthropicProvider(
    AnthropicOptions::fromArray(['apiKey' => 'sk-ant-...'])
);

name()

name(): string
Returns the canonical provider name string. Always returns 'anthropic' (the value of AnthropicOptions::PROVIDER_NAME). The provider name is used internally by the model registry and capability resolution logic to scope entries to this provider.
echo $provider->name(); // 'anthropic'

textModel()

textModel(string $modelId): TextModelInterface
Creates and returns a new AnthropicTextModel bound to this provider’s options. The returned handle is lightweight — no network request is made at construction time. Call ->generate() or ->stream() on the resulting model to send requests to the Anthropic Messages API.
modelId
string
required
A Claude model identifier string. Must match either a model present in the built-in model catalog or one registered via Anthropic::registerModel() / the provider’s model registry.
$model = $provider->textModel('claude-sonnet-4');
When working with the facade, prefer Anthropic::model('claude-sonnet-4') over calling $provider->textModel() directly. The facade ensures the default provider singleton is used consistently throughout the application.

Build docs developers (and LLMs) love