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

ActiveLibrary[API Development](/categories/api)

wdelfuego/anthropic-laravel
===========================

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

v1.2.1(9mo ago)04MITPHPPHP ^8.1.0

Since Jun 11Pushed 9mo agoCompare

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

READMEChangelogDependencies (9)Versions (3)Used By (0)

[![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). This package is based on the excellent work of [Nuno Maduro](https://github.com/nunomaduro) and [Sandro Gehri](https://github.com/gehrisandro).

> **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.

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

[](#table-of-contents)

- [Support Us](#support-us)
- [Get Started](#get-started)
- [Configuration](#configuration)
- [Usage](#usage)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

Support us
----------

[](#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](https://github.com/sponsors/mozex) program. Just click the "**[Sponsor](https://github.com/sponsors/mozex)**" 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
-----------

[](#get-started)

> **Requires [PHP 8.1+](https://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-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)

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 usage examples, take a look at the [mozex/anthropic-php](https://github.com/mozex/anthropic-php) repository.

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 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](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)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance55

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.9% 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 ~37 days

Total

2

Last Release

298d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1326136?v=4)[wdelfuego](/maintainers/wdelfuego)[@wdelfuego](https://github.com/wdelfuego)

---

Top Contributors

[![mozex](https://avatars.githubusercontent.com/u/18025667?v=4)](https://github.com/mozex "mozex (47 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

phpapiclientlaravelsdklanguageprocessingnaturalclaudeanthropicClaude-3-OpusClaude-3-SonnetClaude-3-Haiku

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/wdelfuego-anthropic-laravel/health.svg)](https://phpackages.com/packages/wdelfuego-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-laravel

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

71226.4k1](/packages/mozex-anthropic-laravel)[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)[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/symfony

Symfony Bundle for Gemini

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

PHPackages © 2026

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