Anthropic Claude provider for PapiAI - A simple but powerful PHP library for building AI agents.
composer require papi-ai/anthropicuse PapiAI\Core\Agent;
use PapiAI\Anthropic\AnthropicProvider;
$provider = new AnthropicProvider(
apiKey: $_ENV['ANTHROPIC_API_KEY'],
);
$agent = new Agent(
provider: $provider,
model: AnthropicProvider::MODEL_CLAUDE_SONNET_5,
instructions: 'You are a helpful assistant.',
);
$response = $agent->run('Hello!');
echo $response->text;AnthropicProvider::MODEL_CLAUDE_FABLE_5_1 // 'claude-fable-5-1' (most capable)
AnthropicProvider::MODEL_CLAUDE_OPUS_5 // 'claude-opus-5'
AnthropicProvider::MODEL_CLAUDE_SONNET_5 // 'claude-sonnet-5' (default)
AnthropicProvider::MODEL_CLAUDE_HAIKU_4_5 // 'claude-haiku-4-5' (fastest)
AnthropicProvider::MODEL_CLAUDE_FABLE_5 // 'claude-fable-5'
AnthropicProvider::MODEL_CLAUDE_OPUS_4_8 // 'claude-opus-4-8'
AnthropicProvider::MODEL_CLAUDE_OPUS_4_7 // 'claude-opus-4-7'
AnthropicProvider::MODEL_CLAUDE_OPUS_4_6 // 'claude-opus-4-6'
AnthropicProvider::MODEL_CLAUDE_SONNET_4_6 // 'claude-sonnet-4-6'All of these are active. Haiku 4.5 is the only one with a retirement floor inside a year: not sooner than 15 October 2026.
The constants alias a ClaudeModel enum, which is the source of truth: it knows each model's thinking API, effort levels, whether a tool can be forced, and its retirement floor. Pass the enum's ->value or the constant, both are the same string.
use PapiAI\Anthropic\ClaudeModel;
ClaudeModel::Haiku45->retiresNotBefore(); // '2026-10-15'
ClaudeModel::Fable51->acceptsForcedTools(); // false
ClaudeModel::tryFrom('claude-opus-6'); // null: unknown IDs are assumed newest, never rejectedeffort maps to whichever shape the model's generation accepts. Everything from 4.6 on takes adaptive thinking plus an effort level (low to max); Haiku 4.5 takes a token budget carved out of maxTokens; Fable cannot stop thinking, so none narrows to low rather than sending a block the API rejects.
Fable 5.1 does not accept a forced tool choice. toolChoice of required or a named tool throws a ProviderException before any request is made; auto and none work as normal.
- Tool/function calling
- Vision/multimodal support
- Streaming support
MIT