PHPackages                             joshfinlayau/laravel-anthropic-web - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. joshfinlayau/laravel-anthropic-web

ActiveLibrary[API Development](/categories/api)

joshfinlayau/laravel-anthropic-web
==================================

Laravel client for Anthropic's Claude API with web search and fetch capabilities

v1.0.0(9mo ago)010MITPHPPHP ^8.1CI passing

Since Sep 26Pushed 9mo agoCompare

[ Source](https://github.com/JoshFinlayAU/laravel-anthropic-web)[ Packagist](https://packagist.org/packages/joshfinlayau/laravel-anthropic-web)[ RSS](/packages/joshfinlayau-laravel-anthropic-web/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Laravel Anthropic Web
=====================

[](#laravel-anthropic-web)

[![Tests](https://github.com/JoshFinlayAU/laravel-anthropic-web/workflows/Tests/badge.svg)](https://github.com/JoshFinlayAU/laravel-anthropic-web/actions)[![Latest Stable Version](https://camo.githubusercontent.com/2023c0b732e69e62f31158e1960156c75b34db861ddb5c20c0e46189d97899ad/68747470733a2f2f706f7365722e707567782e6f72672f6a6f736866696e6c617961752f6c61726176656c2d616e7468726f7069632d7765622f762f737461626c65)](https://packagist.org/packages/joshfinlayau/laravel-anthropic-web)[![License](https://camo.githubusercontent.com/37c6aeabcdb9364407f2a39e72c07c554242ccbac2e256bd7b24c5889d7e3af2/68747470733a2f2f706f7365722e707567782e6f72672f6a6f736866696e6c617961752f6c61726176656c2d616e7468726f7069632d7765622f6c6963656e7365)](https://packagist.org/packages/joshfinlayau/laravel-anthropic-web)

A Laravel package for Anthropic's Claude API with web search and fetch capabilities.

Features
--------

[](#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
------------

[](#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
-----------

[](#basic-usage)

### Simple Text Completion

[](#simple-text-completion)

```
use JoshFinlayAU\LaravelAnthropicWeb\Facades\AnthropicWeb;

$response = AnthropicWeb::complete('What are the latest developments in AI?');
echo $response;
```

### Web Search

[](#web-search)

```
$result = AnthropicWeb::completeWithWebSearch(
    'What are the current interest rates in Australia?',
    searchOptions: ['max_uses' => 3]
);
```

### Web Fetch

[](#web-fetch)

```
$analysis = AnthropicWeb::completeWithWebFetch(
    'Analyze the content at https://example.com/article',
    fetchOptions: [
        'citations' => ['enabled' => true],
        'allowed_domains' => ['example.com']
    ]
);
```

### Combined Web Tools

[](#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

[](#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
--------------

[](#advanced-usage)

### Custom Tool Configuration

[](#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

[](#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
-------------

[](#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
----------------

[](#available-models)

- `claude-opus-4-1-20250805` (Most capable)
- `claude-opus-4-20250514`
- `claude-sonnet-4-20250514` (Recommended default)
- `claude-3-7-sonnet-20250219`
- `claude-3-5-haiku-latest` (Fastest)

Web Tools
---------

[](#web-tools)

### Web Search Tool

[](#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

[](#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
--------------

[](#error-handling)

```
try {
    $response = AnthropicWeb::complete('Your prompt here');
} catch (\Exception $e) {
    Log::error('Anthropic API failed: ' . $e->getMessage());
}
```

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 9.0+

License
-------

[](#license)

MIT

Contributing
------------

[](#contributing)

Pull requests welcome. Please include tests for new features.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance57

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

281d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/233381063?v=4)[Josh Finlay](/maintainers/JoshFinlayAU)[@JoshFinlayAU](https://github.com/JoshFinlayAU)

---

Top Contributors

[![JoshFinlayAU](https://avatars.githubusercontent.com/u/233381063?v=4)](https://github.com/JoshFinlayAU "JoshFinlayAU (11 commits)")

---

Tags

laravelaiclaudeweb-search anthropicweb-fetch

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/joshfinlayau-laravel-anthropic-web/health.svg)

```
[![Health](https://phpackages.com/badges/joshfinlayau-laravel-anthropic-web/health.svg)](https://phpackages.com/packages/joshfinlayau-laravel-anthropic-web)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k108.5M887](/packages/laravel-socialite)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.0k](/packages/simplestats-io-laravel-client)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.9k3](/packages/defstudio-telegraph)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
