joshfinlayau/laravel-anthropic-web
Composer 安装命令:
composer require joshfinlayau/laravel-anthropic-web
包简介
Laravel client for Anthropic's Claude API with web search and fetch capabilities
README 文档
README
A Laravel package for Anthropic's Claude API with web search and fetch capabilities.
Features
This package supports Claude's web tools that other packages don't:
- Web search for current information
- Web fetch to analyze content from URLs
- Latest Claude models (Sonnet 4, Opus 4.1)
- JSON response formatting with schema validation
- Proper beta headers for new API features
Useful for applications requiring AI with real-time web data access.
Installation
composer require joshfinlayau/laravel-anthropic-web
Publish the config file:
php artisan vendor:publish --tag=anthropic-web-config
Add your API key to .env:
ANTHROPIC_API_KEY=your-api-key-here
Basic Usage
Simple Text Completion
use JoshFinlayAU\LaravelAnthropicWeb\Facades\AnthropicWeb; $response = AnthropicWeb::complete('What are the latest developments in AI?'); echo $response;
Web Search
$result = AnthropicWeb::completeWithWebSearch( 'What are the current interest rates in Australia?', searchOptions: ['max_uses' => 3] );
Web Fetch
$analysis = AnthropicWeb::completeWithWebFetch( 'Analyze the content at https://example.com/article', fetchOptions: [ 'citations' => ['enabled' => true], 'allowed_domains' => ['example.com'] ] );
Combined Web Tools
$research = AnthropicWeb::completeWithWebTools( 'Research the latest trends in renewable energy and analyze the top 3 articles you find', searchOptions: ['max_uses' => 5], fetchOptions: ['citations' => ['enabled' => true]] );
JSON Response Format
// Simple JSON response $data = AnthropicWeb::completeJson('Return information about Paris as JSON'); // JSON with schema validation $schema = [ 'type' => 'object', 'properties' => [ 'name' => ['type' => 'string'], 'population' => ['type' => 'integer'], 'country' => ['type' => 'string'] ] ]; $cityData = AnthropicWeb::completeJson( 'Return information about Tokyo', $schema ); // JSON response with web search $currentData = AnthropicWeb::completeJsonWithWebSearch( 'Find current stock price for Apple and return as JSON', ['type' => 'object', 'properties' => ['symbol' => ['type' => 'string'], 'price' => ['type' => 'number']]] );
Advanced Usage
Custom Tool Configuration
$searchTool = AnthropicWeb::webSearchTool([ 'max_uses' => 5, 'allowed_domains' => ['reuters.com', 'bbc.com'], 'user_location' => AnthropicWeb::userLocation('Sydney', 'NSW', 'AU', 'Australia/Sydney') ]); $request = AnthropicWeb::buildMessageRequest( 'claude-sonnet-4-20250514', [['role' => 'user', 'content' => 'Latest news about climate change']], 4000, [$searchTool] ); $response = AnthropicWeb::createMessage($request);
Streaming Responses
$stream = AnthropicWeb::createStreamedMessage([ 'model' => 'claude-sonnet-4-20250514', 'max_tokens' => 4000, 'messages' => [['role' => 'user', 'content' => 'Tell me about quantum computing']], 'tools' => [AnthropicWeb::webSearchTool()] ]); foreach ($stream as $chunk) { echo $chunk['content'][0]['text'] ?? ''; }
Configuration
The config file allows you to set defaults:
return [ 'api_key' => env('ANTHROPIC_API_KEY'), 'models' => [ 'default' => 'claude-sonnet-4-20250514', 'fast' => 'claude-3-5-haiku-latest', 'powerful' => 'claude-opus-4-1-20250805', ], 'web_tools' => [ 'search' => ['max_uses' => 5], 'fetch' => ['max_uses' => 10, 'citations_enabled' => true], ], ];
Available Models
claude-opus-4-1-20250805(Most capable)claude-opus-4-20250514claude-sonnet-4-20250514(Recommended default)claude-3-7-sonnet-20250219claude-3-5-haiku-latest(Fastest)
Web Tools
Web Search Tool
Searches the internet for current information:
AnthropicWeb::webSearchTool([ 'max_uses' => 5, 'allowed_domains' => ['example.com'], 'blocked_domains' => ['spam.com'], 'user_location' => [ 'city' => 'Brisbane', 'region' => 'Queensland', 'country' => 'AU', 'timezone' => 'Australia/Brisbane' ] ])
Web Fetch Tool
Fetches and analyzes specific web pages:
AnthropicWeb::webFetchTool([ 'max_uses' => 10, 'allowed_domains' => ['trusted-site.com'], 'citations' => ['enabled' => true], 'max_content_tokens' => 100000 ])
Error Handling
try { $response = AnthropicWeb::complete('Your prompt here'); } catch (\Exception $e) { Log::error('Anthropic API failed: ' . $e->getMessage()); }
Requirements
- PHP 8.1+
- Laravel 9.0+
License
MIT
Contributing
Pull requests welcome. Please include tests for new features.
joshfinlayau/laravel-anthropic-web 适用场景与选型建议
joshfinlayau/laravel-anthropic-web 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「ai」 「web-search」 「claude」 「anthropic」 「web-fetch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 joshfinlayau/laravel-anthropic-web 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 joshfinlayau/laravel-anthropic-web 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 joshfinlayau/laravel-anthropic-web 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Crawlzone is a fast asynchronous internet crawling framework aiming to provide open source web search and testing solution. It can be used for a wide range of purposes, from extracting and indexing structured data to monitoring and automated testing.
Estimate AI API costs before making expensive calls
Interactive CLI that generates customized Claude Code markdown files (CLAUDE.md, commands, agents) for PHP projects with Symfony, Laravel, Rector, PHPStan, PHP-CS-Fixer, GrumPHP and more.
Claude Code skill for Drupal module development — acts as a senior Drupal architect with deep knowledge of Drupal 11 core APIs, modern development patterns, and best practices.
Alfabank REST API integration
Laravel wrapper for the Exa.ai API
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-26