PHPackages                             mozex/anthropic-laravel - 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. mozex/anthropic-laravel

ActiveLibrary[API Development](/categories/api)

mozex/anthropic-laravel
=======================

Laravel integration for the Anthropic API: facade, config publishing, install command, testing fakes, messages, streaming, tool use, thinking, and batches.

1.7.0(2mo ago)74331.3k↓21.1%6[1 PRs](https://github.com/mozex/anthropic-laravel/pulls)1MITPHPPHP ^8.2.0CI passing

Since May 1Pushed 3w ago3 watchersCompare

[ Source](https://github.com/mozex/anthropic-laravel)[ Packagist](https://packagist.org/packages/mozex/anthropic-laravel)[ GitHub Sponsors](https://github.com/mozex)[ RSS](/packages/mozex-anthropic-laravel/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (27)Versions (19)Used By (1)

Anthropic Laravel
=================

[](#anthropic-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/160ea7348793ba45afba9c70c8b0f51d594da32efd93834321834fe017fce8f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f7a65782f616e7468726f7069632d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mozex/anthropic-laravel)[![GitHub Checks Workflow Status](https://camo.githubusercontent.com/3447a01b1744624594ea2f7efeab187a955c7e074bcc655907dbc26b3f3ec65a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f7a65782f616e7468726f7069632d6c61726176656c2f636865636b732e796d6c3f6272616e63683d6d61696e266c6162656c3d636865636b73267374796c653d666c61742d737175617265)](https://github.com/mozex/anthropic-laravel/actions/workflows/checks.yml)[![Docs](https://camo.githubusercontent.com/6bae6cab4895bc9b3768db4e7f44e2640da7b03da9635f43f34a1ea306f23e0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d6d6f7a65782e6465762d3130423938313f7374796c653d666c61742d737175617265)](https://mozex.dev/docs/anthropic-laravel/v1)[![License](https://camo.githubusercontent.com/e2bc2324e850d097ec0c0b05940d92d7f46254b0eb1c96e1fb17267a9fbc3235/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6f7a65782f616e7468726f7069632d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mozex/anthropic-laravel)[![Total Downloads](https://camo.githubusercontent.com/5987e1c3799debb50b1f68f3595caac2959aff528fbc9af29b97c20bba2cca1d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f7a65782f616e7468726f7069632d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mozex/anthropic-laravel)

Laravel wrapper for [Anthropic PHP](https://github.com/mozex/anthropic-php), the community-maintained PHP SDK for the [Anthropic API](https://platform.claude.com/docs/en/about-claude/models/overview). Adds a Facade, a publishable config, an install command, and a testing integration that plugs into the service container.

> **[Read the full documentation at mozex.dev](https://mozex.dev/docs/anthropic-laravel/v1)**: searchable docs, version requirements, detailed changelog, and more.

> **Not using Laravel?** Use the framework-agnostic [Anthropic PHP](https://github.com/mozex/anthropic-php) package directly.

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](https://mozex.dev/docs/anthropic-laravel/v1)
- Usage
    - [Messages](https://mozex.dev/docs/anthropic-laravel/v1/usage/messages)
    - [Streaming](https://mozex.dev/docs/anthropic-laravel/v1/usage/streaming)
    - [Tool Use](https://mozex.dev/docs/anthropic-laravel/v1/usage/tool-use)
    - [Thinking](https://mozex.dev/docs/anthropic-laravel/v1/usage/thinking)
    - [Server Tools](https://mozex.dev/docs/anthropic-laravel/v1/usage/server-tools)
    - [Citations](https://mozex.dev/docs/anthropic-laravel/v1/usage/citations)
    - [Token Counting](https://mozex.dev/docs/anthropic-laravel/v1/usage/token-counting)
    - [Models](https://mozex.dev/docs/anthropic-laravel/v1/usage/models)
    - [Batches](https://mozex.dev/docs/anthropic-laravel/v1/usage/batches)
    - [Files](https://mozex.dev/docs/anthropic-laravel/v1/usage/files)
    - [Completions](https://mozex.dev/docs/anthropic-laravel/v1/usage/completions)
- Reference
    - [Configuration](https://mozex.dev/docs/anthropic-laravel/v1/reference/configuration)
    - [Error Handling](https://mozex.dev/docs/anthropic-laravel/v1/reference/error-handling)
    - [Meta Information](https://mozex.dev/docs/anthropic-laravel/v1/reference/meta-information)
    - [Testing](https://mozex.dev/docs/anthropic-laravel/v1/reference/testing)

Support This Project
--------------------

[](#support-this-project)

I maintain this package along with [several other open-source PHP packages](https://mozex.dev/docs) used by thousands of developers every day.

If my packages save you time or help your business, consider [**sponsoring my work on GitHub Sponsors**](https://github.com/sponsors/mozex). Your support lets me keep these packages updated, respond to issues quickly, and ship new features.

Business sponsors get logo placement in package READMEs. [**See sponsorship tiers →**](https://github.com/sponsors/mozex)

Why This Package
----------------

[](#why-this-package)

**`Anthropic::` Facade for everything.** `Anthropic::messages()`, `Anthropic::models()`, `Anthropic::batches()`, `Anthropic::files()`, `Anthropic::completions()`. No client instantiation, no factory setup. The service provider handles it.

**`Anthropic::fake()` in your tests.** Swap the real client with a fake, queue responses, and assert exactly which requests were sent. Pairs with Laravel's existing testing idioms like `Event::fake()` and `Queue::fake()`. [See the testing docs →](https://mozex.dev/docs/anthropic-laravel/v1/reference/testing)

```
use Anthropic\Laravel\Facades\Anthropic;
use Anthropic\Resources\Messages;
use Anthropic\Responses\Messages\CreateResponse;

Anthropic::fake([
    CreateResponse::fake([
        'content' => [['type' => 'text', 'text' => 'Paris is the capital of France.']],
    ]),
]);

// Run your code...

Anthropic::assertSent(Messages::class, function (string $method, array $parameters) {
    return $parameters['model'] === 'claude-sonnet-4-6';
});
```

**One artisan command to set up.** `php artisan anthropic:install` publishes the config file and appends `ANTHROPIC_API_KEY=` to your `.env`. You're ready to go.

**Forward-compatible.** Parameters pass through to the API as-is. When Anthropic ships a new feature, it works in your code the same day. No waiting for a package update.

**Full Anthropic API coverage.** Messages, streaming, tool use, extended thinking, web search, code execution, citations, token counting, and batch processing. Every feature the API supports is available through the Facade.

Installation
------------

[](#installation)

> **Requires [PHP 8.2+](https://www.php.net/releases/)** - see [all version requirements](https://mozex.dev/docs/anthropic-laravel/v1/requirements)

```
composer require mozex/anthropic-laravel
```

Run the install command:

```
php artisan anthropic:install
```

This publishes `config/anthropic.php` and appends `ANTHROPIC_API_KEY=` to your `.env`. Set your key from the [Anthropic Console](https://platform.claude.com/settings/keys):

```
ANTHROPIC_API_KEY=sk-ant-...
```

Quick Start
-----------

[](#quick-start)

Use the `Anthropic` Facade anywhere in your app:

```
use Anthropic\Laravel\Facades\Anthropic;

$response = Anthropic::messages()->create([
    'model' => 'claude-sonnet-4-6',
    'max_tokens' => 1024,
    'messages' => [
        ['role' => 'user', 'content' => 'Hello!'],
    ],
]);

echo $response->content[0]->text; // Hello! How can I assist you today?

```

### Streaming

[](#streaming)

Print text as it arrives:

```
$stream = Anthropic::messages()->createStreamed([
    'model' => 'claude-sonnet-4-6',
    'max_tokens' => 1024,
    'messages' => [
        ['role' => 'user', 'content' => 'Tell me a short story.'],
    ],
]);

foreach ($stream as $response) {
    if ($response->type === 'content_block_delta'
        && $response->delta->type === 'text_delta') {
        echo $response->delta->text;
    }
}
```

### Tool Use

[](#tool-use)

Give Claude tools to call, execute them in your code, send results back:

```
$response = Anthropic::messages()->create([
    'model' => 'claude-sonnet-4-6',
    'max_tokens' => 1024,
    'tools' => [
        [
            'name' => 'get_weather',
            'description' => 'Get the current weather in a given location',
            'input_schema' => [
                'type' => 'object',
                'properties' => [
                    'location' => ['type' => 'string'],
                ],
                'required' => ['location'],
            ],
        ],
    ],
    'messages' => [
        ['role' => 'user', 'content' => 'What is the weather in San Francisco?'],
    ],
]);

$response->content[1]->name;              // 'get_weather'
$response->content[1]->input['location']; // 'San Francisco'
```

### Extended Thinking

[](#extended-thinking)

Let Claude reason through complex problems before answering:

```
$response = Anthropic::messages()->create([
    'model' => 'claude-opus-4-6',
    'max_tokens' => 16000,
    'thinking' => ['type' => 'adaptive'],
    'messages' => [
        ['role' => 'user', 'content' => 'What is the GCD of 1071 and 462?'],
    ],
]);

$response->content[0]->thinking; // 'Using the Euclidean algorithm...'
$response->content[1]->text;     // 'The GCD of 1071 and 462 is 21.'
```

The [full documentation](https://mozex.dev/docs/anthropic-laravel/v1) covers every feature: [vision and images](https://mozex.dev/docs/anthropic-laravel/v1/usage/messages), [web search and code execution](https://mozex.dev/docs/anthropic-laravel/v1/usage/server-tools), [document citations](https://mozex.dev/docs/anthropic-laravel/v1/usage/citations), [batch processing](https://mozex.dev/docs/anthropic-laravel/v1/usage/batches), [error handling](https://mozex.dev/docs/anthropic-laravel/v1/reference/error-handling), [testing](https://mozex.dev/docs/anthropic-laravel/v1/reference/testing), and [more](https://mozex.dev/docs/anthropic-laravel/v1).

Resources
---------

[](#resources)

Visit the [documentation site](https://mozex.dev/docs/anthropic-laravel/v1) for searchable docs auto-updated from this repository.

- **[AI Integration](https://mozex.dev/docs/anthropic-laravel/v1/ai-integration)**: Use this package with AI coding assistants via Context7 and Laravel Boost
- **[Requirements](https://mozex.dev/docs/anthropic-laravel/v1/requirements)**: PHP, Laravel, and dependency versions
- **[Changelog](https://mozex.dev/docs/anthropic-laravel/v1/changelog)**: Release history with linked pull requests and diffs
- **[Contributing](https://mozex.dev/docs/anthropic-laravel/v1/contributing)**: Development setup, code quality, and PR guidelines
- **[Questions &amp; Issues](https://mozex.dev/docs/anthropic-laravel/v1/questions-and-issues)**: Bug reports, feature requests, and help
- **[Security](mailto:hello@mozex.dev)**: Report vulnerabilities directly via email

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

59

—

FairBetter than 98% of packages

Maintenance91

Actively maintained with recent releases

Popularity50

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 93.8% 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

Every ~59 days

Recently: every ~11 days

Total

13

Last Release

77d ago

PHP version history (2 changes)1.0.0PHP ^8.1.0

1.3.0PHP ^8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4d33a9cb8263eab6fa251e57fc763c5c6977701e5cafa0edc538c4651bb9780?d=identicon)[mozex](/maintainers/mozex)

---

Top Contributors

[![mozex](https://avatars.githubusercontent.com/u/18025667?v=4)](https://github.com/mozex "mozex (105 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")

---

Tags

aianthropicapi-clientclaudefacadesgenerative-ailaravelllmphpsdkstreamingphpapiclientlaravelsdkaistreamingclaudellmanthropictext-generationgenerative-aitool-useClaude OpusClaude SonnetClaude Haikuthinking

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[mozex/anthropic-php

PHP client for the Anthropic API: messages, streaming, tool use, thinking, web search, code execution, batches, and more.

49552.5k18](/packages/mozex-anthropic-php)[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k9.5M89](/packages/openai-php-laravel)[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

46688.8k5](/packages/deepseek-php-deepseek-php-client)[resend/resend-php

Resend PHP library.

617.2M43](/packages/resend-resend-php)[claude-php/claude-php-sdk-laravel

Laravel integration for the Claude PHP SDK - Anthropic Claude API

5223.2k](/packages/claude-php-claude-php-sdk-laravel)[scriptdevelop/whatsapp-manager

Paquete para manejo de WhatsApp Business API en Laravel

783.8k](/packages/scriptdevelop-whatsapp-manager)

PHPackages © 2026

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