wdelfuego/anthropic-laravel
Composer 安装命令:
composer require wdelfuego/anthropic-laravel
包简介
Anthropic PHP for Laravel is a supercharged PHP API client that allows you to interact with the Anthropic API
关键字:
README 文档
README
Anthropic Laravel is a community-maintained PHP API client that allows you to interact with the Anthropic API. This package is based on the excellent work of Nuno Maduro and Sandro Gehri.
Note: This repository contains the integration code of the Anthropic PHP for Laravel. If you want to use the Anthropic PHP client in a framework-agnostic way, take a look at the mozex/anthropic-php repository.
Table of Contents
- Support Us
- Get Started
- Configuration
- Usage
- Testing
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
Support us
Creating and maintaining open-source projects requires significant time and effort. Your support will help enhance the project and enable further contributions to the PHP community.
Sponsorship can be made through the GitHub Sponsors program. Just click the "Sponsor" button at the top of this repository. Any amount is greatly appreciated, even a contribution as small as $1 can make a big difference and will go directly towards developing and improving this package.
Thank you for considering sponsoring. Your support truly makes a difference!
Get Started
Requires PHP 8.1+
First, install Anthropic via the Composer package manager:
composer require mozex/anthropic-laravel
Next, execute the install command:
php artisan anthropic:install
This will create a config/anthropic.php configuration file in your project, which you can modify to your needs
using environment variables.
Blank environment variable for the Anthropic API key is already appended to your .env file.
ANTHROPIC_API_KEY=sk-...
Finally, you may use the Anthropic facade to access the Anthropic API:
use Anthropic\Laravel\Facades\Anthropic; $result = Anthropic::messages()->create([ 'model' => 'claude-3-opus-20240229', 'max_tokens' => 1024, 'messages' => [ ['role' => 'user', 'content' => 'Hello!'], ], ]); echo $result->content[0]->text; // Hello! How can I assist you today?
Configuration
Configuration is done via environment variables or directly in the configuration file (config/anthropic.php).
Anthropic API Key
Specify your Anthropic API Key. This will be used to authenticate with the Anthropic API - you can find your API key on your Anthropic dashboard, at https://console.anthropic.com/settings/keys.
ANTHROPIC_API_KEY=
Request Timeout
The timeout may be used to specify the maximum number of seconds to wait for a response. By default, the client will time out after 30 seconds.
ANTHROPIC_REQUEST_TIMEOUT=
Usage
For usage examples, take a look at the mozex/anthropic-php repository.
Testing
The Anthropic facade comes with a fake() method that allows you to fake the API responses.
The fake responses are returned in the order they are provided to the fake() method.
All responses are having a fake() method that allows you to easily create a response object by only providing the parameters relevant for your test case.
use Anthropic\Laravel\Facades\Anthropic; use Anthropic\Responses\Completions\CreateResponse; Anthropic::fake([ CreateResponse::fake([ 'completion' => 'awesome!', ]), ]); $completion = Anthropic::completions()->create([ 'model' => 'claude-2.1', 'prompt' => '\n\nHuman: PHP is \n\nAssistant:', 'max_tokens_to_sample' => 100, ]); expect($completion['completion'])->toBe('awesome!');
After the requests have been sent there are various methods to ensure that the expected requests were sent:
// assert completion create request was sent Anthropic::assertSent(Completions::class, function (string $method, array $parameters): bool { return $method === 'create' && $parameters['model'] === 'claude-2.1' && $parameters['prompt'] === 'PHP is '; });
For more testing examples, take a look at the mozex/anthropic-php repository.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
wdelfuego/anthropic-laravel 适用场景与选型建议
wdelfuego/anthropic-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「client」 「language」 「sdk」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wdelfuego/anthropic-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wdelfuego/anthropic-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wdelfuego/anthropic-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Alfabank REST API integration
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-11