adachsoft / ai-integration-anthropic
Anthropic Claude tool-calling SPI adapter for adachsoft/ai-integration.
Package info
gitlab.com/a.adach/ai-integration-anthropic
pkg:composer/adachsoft/ai-integration-anthropic
Requires
- php: >=8.3
- adachsoft/ai-integration: ^0.7.0
- guzzlehttp/guzzle: ^7.0 || ^8.0
Requires (Dev)
- adachsoft/php-code-style: ^0.4.2
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^13.0
- rector/rector: ^2.3
- vlucas/phpdotenv: ^5.6
README
Integration of Anthropic Claude (tool calling) with the adachsoft/ai-integration library.
Version
Current version: 0.1.0 (first public release).
Requirements
- PHP
>= 8.3 guzzlehttp/guzzle^7.0 || ^8.0adachsoft/ai-integration^0.6.3
Installation
composer require adachsoft/ai-integration-anthropic:^0.1.0
Basic usage
Example of wiring the Anthropic SPI provider with the tool-calling facade from adachsoft/ai-integration:
use AdachSoft\AiIntegration\PublicApi\Builder\ToolCallingChatFacadeBuilder;
use AdachSoft\AiIntegrationAnthropic\AnthropicToolCallingChatSpi;
$apiKey = getenv('ANTHROPIC_KEY');
$builder = new ToolCallingChatFacadeBuilder();
$builder->withSpiProvider('anthropic', new AnthropicToolCallingChatSpi($apiKey));
$facade = $builder->build();
More detailed usage examples can be found in the production tests:
tests/Production/ToolCalling/AnthropicProviderProductionTest.phptests/Production/ToolCalling/AnthropicFileToolsConversationProductionTest.php
Anthropic cache configuration
This package exposes an explicit configuration surface for controlling Anthropic ephemeral cache via
ToolCallingChatSpiRequest::$parameters. All cache-related keys are prefixed with ai_integration-.
You can control three independent sections:
ai_integration-cache_system– caching of the system prompt (off,5min,1hour).ai_integration-cache_tools– caching of tool definitions (off,5min,1hour).ai_integration-cache_messages– caching of conversation messages (off,5min,1hour).
When ai_integration-cache_messages is enabled (5min or 1hour), you can also choose how the
message cache is applied using:
ai_integration-cache_messages_strategy– built-in strategies:off,first_user,last_user.
The cache layer is opt-in and non-intrusive – if you do not provide any ai_integration-* keys,
all cache behaviour is disabled and requests behave exactly as before.
For a full description of the configuration format, TTL semantics, beta headers and built-in message cache strategies, see:
docs/CACHE_STRATEGIES.md
Tests
The default phpunit.xml configuration defines two test suites:
unit– unit tests (no production calls).production– production/integration tests that require a real Anthropic API key.
Example commands:
# All tests
vendor/bin/phpunit
# Only unit tests
vendor/bin/phpunit --testsuite unit
# Only production tests (requires ANTHROPIC_KEY)
ANTHROPIC_KEY=... vendor/bin/phpunit --testsuite production