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
=======================

Anthropic PHP for Laravel is a supercharged PHP API client that allows you to interact with the Anthropic API

1.3.3(2mo ago)71226.4k↓11.1%61MITPHPPHP ^8.2.0CI passing

Since May 1Pushed 1mo 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 1mo ago

READMEChangelog (10)Dependencies (18)Versions (14)Used By (1)

[![Latest Version on Packagist](https://camo.githubusercontent.com/160ea7348793ba45afba9c70c8b0f51d594da32efd93834321834fe017fce8f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f7a65782f616e7468726f7069632d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mozex/anthropic-laravel)[![GitHub Tests Workflow Status](https://camo.githubusercontent.com/44dd5676927f9b6039dfcf5a60f7c497f13b456f31d6d7d866e17bbb17bc31aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f7a65782f616e7468726f7069632d6c61726176656c2f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/mozex/anthropic-laravel/actions/workflows/tests.yml)[![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)

---

**Anthropic Laravel** is a community-maintained PHP API client that allows you to interact with the [Anthropic API](https://docs.anthropic.com/claude/docs/intro-to-claude).

> **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](https://github.com/mozex/anthropic-php) repository.

Why Anthropic Laravel?
----------------------

[](#why-anthropic-laravel)

With the official Anthropic SDK and Laravel's own AI SDK available, you might wonder which to use. Here's how they compare:

**Anthropic Laravel****Laravel AI SDK****Official Anthropic SDK****Anthropic API coverage**Full — messages, streaming, tool use, vision, batches, models, adaptive thinking, web search, code execution, citations, token countingUnified API across providers — covers core featuresFull**Multi-provider support**Anthropic onlyOpenAI, Anthropic, Gemini, Groq, xAIAnthropic only**Laravel integration**Facade, config publishing, service providerNative — agents, queuing, conversation memoryNone — framework-agnostic**Testing**`Anthropic::fake()` with per-resource assertions, full parameter inspection, and response mocking at the API levelHigher-level fakes per capability — no direct API parameter assertionsNone built-in**Laravel version support**11+12+Any (no Laravel dependency)**PHP version**8.2+8.3+8.1+**New Anthropic features**Same-day supportFollows unified release cycleSame-day support### Choose Anthropic Laravel when you:

[](#choose-anthropic-laravel-when-you)

- Need **full access to every Anthropic API feature** — including batches, adaptive thinking, web search, code execution, citations, token counting, and model management
- Want **granular test control** — `Anthropic::fake()` lets you mock exact API responses and assert on specific resource methods and parameters, something no other Laravel integration offers at this level
- Want a **Laravel-native experience** (Facades, config, testing) without sacrificing API depth
- Are on **Laravel 11** (Laravel AI SDK requires 12+)
- Want **same-day support** when Anthropic ships new features
- Prefer a **thin, focused wrapper** over a multi-provider abstraction

### Choose Laravel AI SDK when you:

[](#choose-laravel-ai-sdk-when-you)

- Need to **switch between AI providers** (OpenAI, Gemini, etc.) with one codebase
- Want built-in **agent architecture** with conversation memory and provider failover
- Are building a new **Laravel 12+** project and don't need Anthropic-specific features

Both packages can coexist — use Laravel AI SDK for multi-provider features and Anthropic Laravel for deep Anthropic integration.

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

[](#table-of-contents)

- [Why Anthropic Laravel?](#why-anthropic-laravel)
- [Support This Project](#support-this-project)
- [Get Started](#get-started)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Adaptive Thinking](#adaptive-thinking)
    - [Web Search](#web-search)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

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

[](#support-this-project)

I maintain this package along with [several other open-source PHP packages](https://github.com/mozex?tab=repositories&q=&type=source) 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)

Get Started
-----------

[](#get-started)

> **Requires [PHP 8.2+](https://www.php.net/releases/)**

First, install Anthropic via the [Composer](https://getcomposer.org/) 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-sonnet-4-6',
    'max_tokens' => 1024,
    'messages' => [
        ['role' => 'user', 'content' => 'Hello!'],
    ],
]);

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

```

Configuration
-------------

[](#configuration)

Configuration is done via environment variables or directly in the configuration file (`config/anthropic.php`).

### Anthropic API Key

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

```
ANTHROPIC_API_KEY=
```

### Request Timeout

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

[](#usage)

For detailed usage examples, take a look at the [mozex/anthropic-php](https://github.com/mozex/anthropic-php) repository.

The following resources are available through the `Anthropic` facade:

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

// Messages (primary API)
Anthropic::messages()->create([...]);
Anthropic::messages()->createStreamed([...]);
Anthropic::messages()->countTokens([...]);

// Models
Anthropic::models()->list();
Anthropic::models()->retrieve('claude-sonnet-4-6');

// Message Batches
Anthropic::batches()->create([...]);
Anthropic::batches()->retrieve('msgbatch_...');
Anthropic::batches()->list();
Anthropic::batches()->cancel('msgbatch_...');
Anthropic::batches()->delete('msgbatch_...');
Anthropic::batches()->results('msgbatch_...');

// Legacy Completions
Anthropic::completions()->create([...]);
```

### Adaptive Thinking

[](#adaptive-thinking)

Use adaptive thinking to let Claude adjust its reasoning depth dynamically:

```
$result = Anthropic::messages()->create([
    'model' => 'claude-opus-4-6',
    'max_tokens' => 16000,
    'temperature' => 1, // required for thinking
    'thinking' => [
        'type' => 'enabled',
        'budget_tokens' => 10000,
    ],
    'messages' => [
        ['role' => 'user', 'content' => 'Explain quantum entanglement.'],
    ],
]);
```

### Web Search

[](#web-search)

Enable Claude to search the web and cite sources in its responses:

```
$result = Anthropic::messages()->create([
    'model' => 'claude-sonnet-4-6',
    'max_tokens' => 1024,
    'tools' => [
        [
            'type' => 'web_search_20250305',
            'name' => 'web_search',
        ],
    ],
    'messages' => [
        ['role' => 'user', 'content' => 'What are the latest developments in fusion energy?'],
    ],
]);
```

Testing
-------

[](#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 have 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\Resources\Messages;
use Anthropic\Responses\Messages\CreateResponse;

Anthropic::fake([
    CreateResponse::fake([
        'id' => 'msg_test',
    ]),
]);

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

expect($result)->id->toBe('msg_test');
```

After the requests have been sent there are various methods to ensure that the expected requests were sent:

```
// assert a messages create request was sent
Anthropic::assertSent(Messages::class, function (string $method, array $parameters): bool {
    return $method === 'create' &&
        $parameters['model'] === 'claude-sonnet-4-6';
});
```

You can also assert on specific resources:

```
Anthropic::messages()->assertSent(function (string $method, array $parameters): bool {
    return $method === 'create';
});
```

Other available assertion methods:

```
// assert that nothing was sent
Anthropic::assertNothingSent();

// assert that a specific resource was not called
Anthropic::assertNotSent(Messages::class);
```

For more testing examples, take a look at the [mozex/anthropic-php](https://github.com/mozex/anthropic-php#testing) repository.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Mozex](https://github.com/mozex)
- [Nuno Maduro](https://github.com/nunomaduro) and [Sandro Gehri](https://github.com/gehrisandro) for their work on [openai-php](https://github.com/openai-php/client), which inspired this package
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance88

Actively maintained with recent releases

Popularity49

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 91% 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 ~84 days

Recently: every ~109 days

Total

9

Last Release

74d 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 (71 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-ailaravelllmphpsdkstreamingphpapiclientlaravelsdklanguageprocessingnaturalclaudeanthropicClaude OpusClaude SonnetClaude Haiku

###  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

[openai-php/laravel

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

3.7k7.6M74](/packages/openai-php-laravel)[mozex/anthropic-php

Anthropic PHP is a supercharged community-maintained PHP API client that allows you to interact with Anthropic API.

46365.1k13](/packages/mozex-anthropic-php)[google-gemini-php/laravel

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

614397.1k4](/packages/google-gemini-php-laravel)[google-gemini-php/symfony

Symfony Bundle for Gemini

149.4k1](/packages/google-gemini-php-symfony)

PHPackages © 2026

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