PHPackages                             aisdk/anthropic - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. aisdk/anthropic

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aisdk/anthropic
===============

Official Anthropic provider for the PHP AI SDK.

v0.8.0(1mo ago)016↓50%MITPHPPHP ^8.3CI passing

Since Jun 30Pushed 4w agoCompare

[ Source](https://github.com/phpaisdk/anthropic)[ Packagist](https://packagist.org/packages/aisdk/anthropic)[ Docs](https://github.com/phpaisdk/anthropic)[ RSS](/packages/aisdk-anthropic/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (10)Dependencies (12)Versions (12)Used By (0)

aisdk/anthropic
===============

[](#aisdkanthropic)

[![GitHub Workflow Status](https://camo.githubusercontent.com/1382b16cc950be19b77db2314c8d47751fee430ec021411a8026cdde655b2a88/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706870616973646b2f616e7468726f7069632f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473)](https://github.com/phpaisdk/anthropic/actions)[![Total Downloads](https://camo.githubusercontent.com/6df23a6d14c49288bb57ade634528a4030ce7bd0877b6b561ff4ee086c4f549d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616973646b2f616e7468726f706963)](https://packagist.org/packages/aisdk/anthropic)[![Latest Version](https://camo.githubusercontent.com/6ee03a39c2487ed12780306925aea7fa504709cc1529272bd2d6be8b9dc7cd5e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616973646b2f616e7468726f706963)](https://packagist.org/packages/aisdk/anthropic)[![License](https://camo.githubusercontent.com/f2d58193cf271c12e07ac78946110efacfb385ad4a39e18178647ab8a3bb2f40/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616973646b2f616e7468726f706963)](https://packagist.org/packages/aisdk/anthropic)[![Why PHP in 2026](https://camo.githubusercontent.com/d2b9305e630caf7daae4ca023de39ece0b885c37461629d42961533f00868b76/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5768795f5048502d696e5f323032362d3741383645383f7374796c653d666c61742d737175617265266c6162656c436f6c6f723d313831383162)](https://whyphp.dev)

---

Official Anthropic provider for the PHP AI SDK.

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

[](#installation)

```
composer require aisdk/anthropic
```

Basic Usage
-----------

[](#basic-usage)

```
use AiSdk\Anthropic;
use AiSdk\Generate;

$result = Generate::text()
    ->model(Anthropic::model('claude-sonnet-4'))
    ->instructions('Write short, clear answers.')
    ->prompt('Explain closures in PHP.')
    ->run();

echo $result->text;
```

Default model shorthand:

```
Generate::model(Anthropic::model('claude-sonnet-4'));

$result = Generate::text('Explain closures in PHP.')->run();
```

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

[](#configuration)

### Environment Variables

[](#environment-variables)

VariableDescriptionDefault`ANTHROPIC_API_KEY`API key for authenticationRequired`ANTHROPIC_BASE_URL`Base URL for API requests`https://api.anthropic.com/v1``ANTHROPIC_VERSION`API version header`2023-06-01`### Programmatic Configuration

[](#programmatic-configuration)

```
$provider = Anthropic::create([
    'apiKey' => 'sk-ant-...',
    'baseUrl' => 'https://api.anthropic.com/v1',
    'version' => '2023-06-01',
    'headers' => ['anthropic-beta' => 'extended-thinking-2025-05-14'],
]);
```

Supported Capabilities
----------------------

[](#supported-capabilities)

CapabilitySupportText generationNativeStreamingNativeTool callingNativeStructured outputAdapted (forced tool use)ReasoningNative (`thinking` blocks)Text inputNativeImage inputNativeFile inputNative (documents)Streaming
---------

[](#streaming)

```
use AiSdk\Anthropic;
use AiSdk\Generate;

$stream = Generate::text('Tell me a story.')
    ->model(Anthropic::model('claude-sonnet-4'))
    ->stream();

foreach ($stream->chunks() as $chunk) {
    echo $chunk;
}

$result = $stream->run();
```

Structured Output
-----------------

[](#structured-output)

Anthropic does not natively support `json_schema` response format. Structured output is adapted through forced tool use:

```
use AiSdk\Anthropic;
use AiSdk\Generate;
use AiSdk\Schema;

$result = Generate::text()
    ->model(Anthropic::model('claude-sonnet-4'))
    ->prompt('Extract the city and country from: Lahore, Pakistan.')
    ->output(Schema::object(
        name: 'address',
        properties: [
            Schema::string(name: 'city')->required(),
            Schema::string(name: 'country')->required(),
        ],
    ))
    ->run();
```

Reasoning
---------

[](#reasoning)

```
use AiSdk\Anthropic;
use AiSdk\Generate;
use AiSdk\Reasoning;

$result = Generate::text('Solve: what is 2+2?')
    ->model(Anthropic::model('claude-sonnet-4'))
    ->reasoning(Reasoning::effort('high'))
    ->run();
```

Tools
-----

[](#tools)

```
use AiSdk\Anthropic;
use AiSdk\Generate;
use AiSdk\Schema;
use AiSdk\Tool;

$weather = Tool::make('weather', 'Get current weather')
    ->input(Schema::string(name: 'city')->required())
    ->run(fn (string $city): string => "Sunny in {$city}");

$result = Generate::text()
    ->model(Anthropic::model('claude-sonnet-4'))
    ->prompt('What is the weather in Lahore?')
    ->tool($weather)
    ->run();
```

Model IDs and Capabilities
--------------------------

[](#model-ids-and-capabilities)

Anthropic model IDs pass through unchanged and do not need to be registered. The package does not ship a model inventory; the Anthropic API remains the authority on whether a particular model accepts a requested feature.

Capabilities describe what the Anthropic adapter can serialize. The Anthropic API returns a normalized SDK exception if the selected model or requested feature is rejected.

Provider-Specific Options
-------------------------

[](#provider-specific-options)

Raw provider options can be passed as an escape hatch:

```
$result = Generate::text('Hello')
    ->model(Anthropic::model('claude-sonnet-4'))
    ->providerOptions('anthropic', [
        'raw' => ['top_k' => 40],
    ])
    ->run();
```

Testing
-------

[](#testing)

```
composer test
```

Documentation
-------------

[](#documentation)

- [PHP AI SDK documentation](https://phpaisdk.com/docs)
- [Anthropic documentation](https://phpaisdk.com/docs/anthropic)

Community
---------

[](#community)

- [Contributing](https://github.com/phpaisdk/.github/blob/main/CONTRIBUTING.md)
- [Support](https://github.com/phpaisdk/.github/blob/main/SUPPORT.md)
- For private security reports, email .

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance94

Actively maintained with recent releases

Popularity8

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

Every ~1 days

Total

11

Last Release

31d ago

### Community

Maintainers

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

---

Top Contributors

[![RanaMoizHaider](https://avatars.githubusercontent.com/u/58527494?v=4)](https://github.com/RanaMoizHaider "RanaMoizHaider (15 commits)")

---

Tags

aiclaudellmanthropicaisdk

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

326127.9k1](/packages/cognesy-instructor-php)[llm-agents/agents

LLM Agents PHP SDK - Autonomous Language Model Agents for PHP

16918.3k9](/packages/llm-agents-agents)[wordpress/ai-provider-for-anthropic

AI Provider for Anthropic for the PHP AI Client SDK. Works as both a Composer package and WordPress plugin.

221.3k](/packages/wordpress-ai-provider-for-anthropic)[soukicz/llm

LLM client with support for cache, tools and async requests

4417.3k](/packages/soukicz-llm)[mohamed-ashraf-elsaed/claude-agent-sdk-laravel

Anthropic Claude Agent SDK for PHP &amp; Laravel — build AI agents with tool use, sandboxing, MCP servers, subagents, hooks, and structured output via the Claude Code CLI

161.1k](/packages/mohamed-ashraf-elsaed-claude-agent-sdk-laravel)[dykyi-roman/awesome-claude-code

Claude Code extension for PHP: audits (architecture, DDD, security, performance, PSR, design patterns, Docker, CI/CD, tests, docs), 3-level code review, automated bug fix, generators (DDD, CQRS, GoF patterns, PSR, tests, documentation, Docker, CI/CD), code explanation, refactoring. 26 commands, 62 agents, 259 skills.

931.4k](/packages/dykyi-roman-awesome-claude-code)

PHPackages © 2026

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