PHPackages                             wpai-inc/anthropic-sdk-php - 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. wpai-inc/anthropic-sdk-php

ActiveLibrary[API Development](/categories/api)

wpai-inc/anthropic-sdk-php
==========================

This library provides convenient access to the Anthropic REST API from server-side PHP

0.2.1(1y ago)2395.9k↓25%5[2 issues](https://github.com/wpai-inc/anthropic-sdk-php/issues)[1 PRs](https://github.com/wpai-inc/anthropic-sdk-php/pulls)1MITPHPPHP ^8.0

Since Mar 8Pushed 1y ago2 watchersCompare

[ Source](https://github.com/wpai-inc/anthropic-sdk-php)[ Packagist](https://packagist.org/packages/wpai-inc/anthropic-sdk-php)[ RSS](/packages/wpai-inc-anthropic-sdk-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (6)Used By (1)

Anthropic PHP SDK
=================

[](#anthropic-php-sdk)

This library provides convenient access to the Anthropic REST API from server-side PHP

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

[](#installation)

```
composer require wpai-inc/anthropic-sdk-php
```

Usage
-----

[](#usage)

Set your API key in the constructor:

```
$anthropic = new \WpAi\Anthropic\AnthropicAPI($apiKey);
```

### Messages Resource

[](#messages-resource)

The only resource available is `/messages`. Note, `/completions` is deprecated and so isn't available in this library.

```
$messages = [
    [
        'role' => 'user',
        'content' => 'How can you help me?',
    ],
];
$options = [
    'model' => 'claude-3-opus-20240229',
    'maxTokens' => 1024,
    'messages' => $messages,
];

$anthropic->messages()->create($options);
```

The options above are required. You may also set them fluently like this:

```
$anthropic->messages()->maxTokens(2048)->create($messages);
```

All other optional [options](https://docs.anthropic.com/claude/reference/messages_post) can be set in the same ways.

To include additional HTTP headers in the request, such as those required for enabling extended token limits, pass an array as the second argument to the `create()` method. For example, to enable support for 8192 max tokens:

```
$response = Anthropic::messages()->create($query, [ 'anthropic-beta' => 'max-tokens-3-5-sonnet-2024-07-15' ]);
```

#### Stream

[](#stream)

A streamed response follows all of the same options as `create()` but may be invoked with:

```
$anthropic->messages()->stream($options);

while (! $stream->eof()) {
    echo $stream->read(1024);
    ob_flush();
    flush();
}
```

You may set extra HTTP headers by passing an array as a second argument to `stream()`.

Laravel
-------

[](#laravel)

This library may also be used in Laravel.

```
use WpAi\Anthropic\Facades\Anthropic;

// Create a message
$response = Anthropic::messages()
    ->model('claude-v1')
    ->maxTokens(100)
    ->messages([
        ['role' => 'user', 'content' => 'Hello, Claude!'],
    ])
    ->create();

// Stream a message
$stream = Anthropic::messages()
    ->model('claude-v1')
    ->maxTokens(100)
    ->messages([
        ['role' => 'user', 'content' => 'Tell me a story.'],
    ])
    ->stream();
```

Publish the config with:

```
php artisan vendor:publish --provider="WpAi\Anthropic\Providers\AnthropicServiceProvider"
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% 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 ~76 days

Total

3

Last Release

648d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7989f813a27a67e7c199f787b950946508da42d6e1d491788b06ebbafdaec820?d=identicon)[gregwpai](/maintainers/gregwpai)

---

Top Contributors

[![greghunt](https://avatars.githubusercontent.com/u/1238407?v=4)](https://github.com/greghunt "greghunt (15 commits)")[![giltotherescue](https://avatars.githubusercontent.com/u/371250?v=4)](https://github.com/giltotherescue "giltotherescue (3 commits)")[![wesleyfantinel](https://avatars.githubusercontent.com/u/3750220?v=4)](https://github.com/wesleyfantinel "wesleyfantinel (3 commits)")

### Embed Badge

![Health badge](/badges/wpai-inc-anthropic-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/wpai-inc-anthropic-sdk-php/health.svg)](https://phpackages.com/packages/wpai-inc-anthropic-sdk-php)
```

###  Alternatives

[skagarwal/google-places-api

Google Places Api

1913.0M8](/packages/skagarwal-google-places-api)[dcblogdev/laravel-microsoft-graph

A Laravel Microsoft Graph API (Office365) package

168285.5k1](/packages/dcblogdev-laravel-microsoft-graph)[vluzrmos/slack-api

Wrapper for Slack.com WEB API.

102589.1k3](/packages/vluzrmos-slack-api)[smodav/mpesa

M-Pesa API implementation

16363.7k1](/packages/smodav-mpesa)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[grantholle/powerschool-api

A Laravel package to make interacting with PowerSchool less painful.

1715.6k1](/packages/grantholle-powerschool-api)

PHPackages © 2026

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