kipchak/driver-anthropic
Composer 安装命令:
composer require kipchak/driver-anthropic
包简介
An Anthropic driver for the Kipchak API Development Kit (ADK)
README 文档
README
A fully typed Anthropic driver for the Kipchak API Development Kit. Built on the official Anthropic PHP SDK, it provides multiple named connections, automatic default model injection, and clean access to the Messages API including streaming and tool use.
Requirements
- PHP 8.4 or 8.5
- Kipchak ^2 || ^3
kipchak/driver-config^1anthropic-ai/sdk^0.36
Versions
- 2.0 — upgrades
anthropic-ai/sdkto ^0.36 and adds PHP 8.5 support. The driver's config (includingmax_retries) and message API are unchanged; if you useraw()to call the SDK directly, review the SDK changes. Requireskipchak/core: ^2 || ^3. - 1.x —
anthropic-ai/sdk^0.6,kipchak/core^2.
See the Kipchak upgrade guide for details.
Installation
composer require kipchak/driver-anthropic
Initialise
Add to your drivers/drivers.php:
\Kipchak\Driver\Anthropic\Anthropic::initialise($container);
Configuration
Create config/kipchak.anthropic.php:
<?php
use function Kipchak\Core\env;
return [
'connections' => [
'default' => [
'api_key' => env('ANTHROPIC_API_KEY', ''),
'default_model' => env('ANTHROPIC_DEFAULT_MODEL', 'claude-sonnet-4-6'),
],
],
];
| Key | Required | Description |
|---|---|---|
api_key | Yes | Anthropic API key |
default_model | No | Model injected automatically when none is specified on a call |
max_retries | No | Override the SDK default of 2 automatic retries |
Usage
use Kipchak\Driver\Anthropic\Anthropic;
$anthropic = Anthropic::get(); // 'default' connection
$anthropic = Anthropic::get('secondary'); // named connection
Creating a Message
$response = $anthropic->messages()->create(
messages: [
['role' => 'user', 'content' => 'What is the capital of France?'],
],
);
echo $response->content[0]->text; // 'The capital of France is Paris.'
The configured default_model is applied automatically. Pass model: explicitly to override:
$response = $anthropic->messages()->create(
messages: [['role' => 'user', 'content' => 'Hello']],
model: 'claude-haiku-4-5-20251001',
maxTokens: 512,
system: 'You are a concise assistant. Reply in one sentence.',
);
Multi-Turn Conversations
$response = $anthropic->messages()->create(
messages: [
['role' => 'user', 'content' => 'My name is Alice.'],
['role' => 'assistant', 'content' => 'Hello Alice, how can I help?'],
['role' => 'user', 'content' => 'What is my name?'],
],
);
Streaming
$stream = $anthropic->messages()->createStream(
messages: [['role' => 'user', 'content' => 'Tell me a short story.']],
);
foreach ($stream as $event) {
// handle streaming events
}
Tool Use
$tools = [
[
'name' => 'get_weather',
'description' => 'Get the current weather for a location.',
'input_schema' => [
'type' => 'object',
'properties' => [
'location' => ['type' => 'string', 'description' => 'City and country'],
],
'required' => ['location'],
],
],
];
$response = $anthropic->messages()->create(
messages: [['role' => 'user', 'content' => 'What is the weather in Dubai?']],
tools: $tools,
);
foreach ($response->content as $block) {
if ($block->type === 'tool_use') {
$result = callTool($block->name, $block->input);
// Send the tool result back
$followup = $anthropic->messages()->create(
messages: [
['role' => 'user', 'content' => 'What is the weather in Dubai?'],
['role' => 'assistant', 'content' => $response->content],
['role' => 'user', 'content' => [
['type' => 'tool_result', 'tool_use_id' => $block->id, 'content' => $result],
]],
],
tools: $tools,
);
}
}
Raw SDK Access
For anything not covered by the driver wrapper, use raw() to access the full Anthropic SDK client directly:
$client = $anthropic->raw();
Running Tests
composer install
./vendor/bin/phpunit
License
MIT — see LICENSE.
kipchak/driver-anthropic 适用场景与选型建议
kipchak/driver-anthropic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「apis」 「ai」 「microservices」 「claude」 「anthropic」 「Mamluk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kipchak/driver-anthropic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kipchak/driver-anthropic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kipchak/driver-anthropic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The Listener component of the RabbitEvents library.
The Publisher component of the RabbitEvents package.
Laravel common
Laravel support for additional blueprint methods
Laravel comment system
Laravel support for GELF logging
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-02