PHPackages                             alle-ai/anthropic-api-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. alle-ai/anthropic-api-php

ActiveLibrary[API Development](/categories/api)

alle-ai/anthropic-api-php
=========================

The go-to PHP library for the Anthropic API — Messages, streaming, tool use, vision, prompt caching, extended thinking, MCP, Files, Batches. Maintained by Alle-AI.

v2.0.0(2mo ago)2726.6k—3.8%4MITPHPPHP ^8.2CI failing

Since May 4Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Alle-AI/anthropic-api-php)[ Packagist](https://packagist.org/packages/alle-ai/anthropic-api-php)[ Docs](https://github.com/Alle-AI/anthropic-api-php)[ RSS](/packages/alle-ai-anthropic-api-php/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (8)Dependencies (16)Versions (11)Used By (0)

anthropic-api-php
=================

[](#anthropic-api-php)

> The go-to PHP library for the Anthropic API. Maintained by [Alle-AI](https://alle-ai.com).

[![Latest Version](https://camo.githubusercontent.com/dcc0358a0c639b5235a3bca06b3444be30652a035c77de38c1ff5785bb43c7af/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c6c652d61692f616e7468726f7069632d6170692d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alle-ai/anthropic-api-php)[![Total Downloads](https://camo.githubusercontent.com/007cfa0accf4a6aa718e13d8d11bd3b1b09e2597a6ac0bc30d7f47040b43c23b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c6c652d61692f616e7468726f7069632d6170692d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alle-ai/anthropic-api-php)[![PHP Version](https://camo.githubusercontent.com/7a15b59c315c2ede0940f4fabcc0843661ec664517cf12108437b5eefe939603/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616c6c652d61692f616e7468726f7069632d6170692d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alle-ai/anthropic-api-php)[![License](https://camo.githubusercontent.com/18eff49d2dabfba714a44a25c77ca6dfcf3779b354e533d3abb2c71f638b81fa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616c6c652d61692f616e7468726f7069632d6170692d7068702e7376673f7374796c653d666c61742d737175617265)](LICENSE)

A first-class PHP client for the Anthropic Messages API. Built for Claude 4 and beyond — Messages, streaming, tool use, vision, prompt caching, extended thinking, MCP connector, Files, Batches. Works with the direct API, **AWS Bedrock**, and **Google Vertex AI**.

> **Looking for the v1.x docs?** See the [`1.x`](https://github.com/Alle-AI/anthropic-api-php/tree/1.x) branch. The v1 surface (`Alle_AI\Anthropic\AnthropicAPI`) is preserved as a deprecation shim through the v2.x line and removed in v3.0. See [UPGRADING.md](UPGRADING.md).

Features
--------

[](#features)

- **Messages API** — typed requests and responses for `POST /v1/messages`
- **Streaming** — Generator-based SSE iterator with `->toMessage()` aggregator
- **Tool use** — closure tools, class-based tools with reflection-driven JSON Schema, automatic tool-loop helper
- **Vision** — `ImageBlock::fromFile()` / `fromUrl()` / `fromBase64()`
- **Prompt caching** — `cache_control` on any block; `Usage::$cacheReadInputTokens` in the response
- **Extended thinking** — `ThinkingConfig::enabled(budgetTokens: 10_000)` for reasoning models
- **MCP connector** — call any remote MCP server via Anthropic's hosted connector
- **Files API** — `Resources\Files::upload()` / `get()` / `list()` / `delete()` / `downloadTo()`
- **Batches API** — `Resources\Batches` with JSONL results streaming and a `pollUntilDone()` helper
- **Models listing** — `$client->models()->list()` paginated catalog
- **PSR-18 / PSR-17** — bring any HTTP client (Guzzle, Symfony HttpClient, Buzz, …)
- **Retries** — exponential backoff with jitter, honors `Retry-After`, idempotency keys auto-attached
- **PSR-3 logging** — opt-in `LoggingMiddleware` with correlation ids, latency, and request-id
- **Pluggable auth** — API key, Bearer token, **AWS Bedrock** (SigV4), **Google Vertex AI** (ADC + OAuth)

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

[](#installation)

Requires **PHP 8.2 or newer**.

```
composer require alle-ai/anthropic-api-php
```

You'll also need a PSR-18 HTTP client and PSR-17 factories. The most popular choice:

```
composer require guzzlehttp/guzzle nyholm/psr7
```

Quick start
-----------

[](#quick-start)

```
