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.1.0-alpha1(yesterday)02↑2900%MITPHPPHP ^8.3

Since Jun 30Pushed yesterdayCompare

[ 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 today

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

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

[](#aisdkanthropic)

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();
```

Custom Model Registration
-------------------------

[](#custom-model-registration)

Register new Anthropic models without waiting for a package release:

```
use AiSdk\Anthropic;
use AiSdk\Capability;

Anthropic::registerModel('claude-5-sonnet', capabilities: [
    Capability::TextGeneration,
    Capability::Streaming,
    Capability::ToolCalling,
    Capability::StructuredOutput,
    Capability::Reasoning,
    Capability::TextInput,
    Capability::ImageInput,
]);

$result = Generate::text('Hello')
    ->model(Anthropic::model('claude-5-sonnet'))
    ->run();
```

Use `ModelDefinition` only when you need metadata or adapted-capability details.

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

Links
-----

[](#links)

- [Core Package](https://github.com/phpaisdk/core)
- [Project Documentation](https://github.com/phpaisdk)

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance100

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

1d 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 (2 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

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

LLM Agents PHP SDK - Autonomous Language Model Agents for PHP

16612.6k9](/packages/llm-agents-agents)[soukicz/llm

LLM client with support for cache, tools and async requests

4411.4k](/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

171.1k](/packages/mohamed-ashraf-elsaed-claude-agent-sdk-laravel)[stimmt/craft-mcp

MCP (Model Context Protocol) server for Craft CMS

261.3k](/packages/stimmt-craft-mcp)

PHPackages © 2026

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