NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
Packagist
Packagist, #2728 most downloaded on Packagist
PHP client for the Anthropic API: messages, streaming, tool use, thinking, web search, code execution, batches, and more.
Latest stable
1.15.0
Last release 16 days ago
06 Nov 2026
Release timing varies
gaps range from 2 weeks to 1.2 years
Nearly every release is documented
notes for 23 of 23 stable releases
Nothing withdrawn
no release was ever pulled
3 years old
23 releases · first in 2024
Drag across the ruler to compare, or tap a release to open it.
A Messages stream gives its text as it arrives with text(), and the whole message it adds up to with finalMessage(), the same CreateResponse that crea
text(), and the whole message it adds up to with finalMessage(), the same CreateResponse that create() returns. finalText(), currentMessage() and callbacks per event kind (onEvent(), onText(), onThinking(), onContentBlock(), onMessage()) come with them, and all of it works on fake streams.MessageAccumulator folds stream events you read another way into the message they add up to.RefusalFallbackMiddleware falls back on streamed requests too: a refused stream goes on with the next model's events spliced onto it, behind a fallback block, under one message_start.fallback block out of the history you send back, where it used to take only those at the front of a turn.CreateResponse::$stop_reason is nullable, for a message folded from a stream before its message_delta.UPGRADING.md lists the changes that can affect code written against 1.14, such as the nullable stop_reason and a subclass of the Messages StreamResponse that declares one of its new methods.
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.14.0...1.15.0
Your coding agent can read these notes before it upgrades. Set up the MCP server →
withStreamCompletionHandler() on the factory reports each Messages stream's usage once it ends, fails or is dropped. The stream has usage(), model(),
withStreamCompletionHandler() on the factory reports each Messages stream's usage once it ends, fails or is dropped. The stream has usage(), model(), completed() and durationMs().billedInputTokens(), billedOutputTokens(), billedTokens() and rateLimitTokens(), counted across usage.iterations.UPGRADING.md lists the changes that can affect code written against 1.13, such as a transporter of your own needing streamCompletionHandler().
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.13.0...1.14.0
ClientFake answers each call with its method's default fake until you queue a response. preventStrayRequests() makes an unanswered call throw instead.
ClientFake answers each call with its method's default fake until you queue a response. preventStrayRequests() makes an unanswered call throw instead.respondTo() answers calls by resource, method or a closure, beside the queue. assertSentTimes(), assertSentInOrder() and sent() are public, and under Pest expect($fake)->toHaveSent(), toHaveSentTimes(), toHaveSentOn(), toHaveSentInOrder() and toHaveSentNothing() work too.fake() with its status, type and request ID, and TransporterException::fake() stands for a request that got no answer.CreateStreamedResponse::fake() takes a list of events or a CreateResponse, and BatchResultResponse::fake() a list of results. Both carry the same rate-limit headers and request ID as the other fakes.Testing\Blocks builds text, tool use, thinking and web search blocks.Testing\Recorder, a client middleware, records a test's API calls once and replays them from a file afterwards, with no key.batches()->wait() polls a batch until it ends. BatchResponse has isEnded(), and batch results have succeeded(), errored(), canceled() and expired().messages()->fits() checks a request against a token limit, and trimToFit() drops the oldest turns until it fits.UPGRADING.md lists the changes that can affect code written against 1.12, such as a fake with no responses no longer throwing.
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.12.0...1.13.0
Each error status throws its own subclass of ErrorException (BadRequestException, AuthenticationException, BillingException, PermissionDeniedException
ErrorException (BadRequestException, AuthenticationException, BillingException, PermissionDeniedException, NotFoundException, ConflictException, RequestTooLargeException, UnprocessableEntityException, RateLimitException, InternalServerException, ApiTimeoutException, OverloadedException), and an error in the middle of a stream throws the subclass of its type.ErrorException has getRequestId(), getErrorDetails() and getRetryAfter(), and context() gives each API error's request ID, status, type, retry-after and error code to Laravel's exception handler and the Laravel packages of Sentry and Flare.ConnectionException and timeouts TimeoutException, both TransporterExceptions.withOptions() returns a client whose requests carry extra headers, query parameters, betas, an API version, a workspace, a user profile or a retry count; methods that take only an ID get betas this way.Factory::withAuthToken() sends a bearer token, such as a Workload Identity Federation access token; withWorkspaceId() sends anthropic-workspace-id.Factory::withBaseUrl() takes a URL the way the official SDKs read ANTHROPIC_BASE_URL.withTimeout() and withConnectTimeout() set the timeouts of the Guzzle client the factory builds.Anthropic::fromEnvironment() builds a client from ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL and ANTHROPIC_CUSTOM_HEADERS.Factory::withConfig() builds a client from a config array. A misspelt key or a value of the wrong type throws, naming the key.Factory::withMaxRetries() retries connection failures, timeouts and 408, 409, 429 and 5xx responses, waiting what the API asks or backing off; retries are off by default.Factory::withMiddleware() runs code around every HTTP attempt; a middleware that throws RetryableException sends the request again. Factory::withLogger() logs each request, response and retry to a PSR-3 logger, without bodies, headers or query strings.request() sends a request to any API path, returning a RawResponse; iterate() on models(), batches() and files() walks every page of a list.RefusalFallbackMiddleware retries a refused Messages request on the fallback models you list, redeeming the refusal's fallback credit; streamed requests pass through for now.OpenTelemetryMiddleware traces each request with OpenTelemetry's GenAI attributes and sends the trace context.Client::settings() returns what a client sends with every request, never its key.isRetired(), isRetiring(), isRetirementOverdue() and retirementDate().withOptions() shares its queue, and assertSentWithOptions() checks a request's options. RawResponse::fake() answers raw requests, and the list fakes walk with iterate(). ClientFake::onConnection() gives a fake per connection, with assertSentOn() and assertNotSentOn().lifecycle filter, is now sent as key[]=, so the API applies it.ErrorException.getErrorType() returns null for an error type that isn't a string.Anthropic::client(), the factory, withConfig() or withOptions() stays out of a stack trace's arguments, which error trackers such as Flare collect.UPGRADING.md lists the changes that can affect code written against 1.10.
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.10.0...1.12.0
Models responses type lifecycle, line, deprecated_at and retires_at, the server_tools capability, xhigh effort, the disabled and between_tools thinkin…
Factory::withApiVersion() sets the anthropic-version header, so you can opt into API version 2026-10-21; the default stays 2023-06-01.toArray() and array access return fields this release doesn't type yet and fields sent as null, in the API's order, so a response's content can be sent back to the API unchanged.mcp_tool_use with server_name, mcp_tool_result with is_error, mcp_tool_listing), advisor results, toolset_name on computer and browser tool calls, compaction encrypted_content and tool_changes (and keep signature in toArray()), the fallback trigger, input_transformations, and fallback credit (stop_details->fallback_credit_token, usage->fallbackCredit).signature, caller, toolset_name, server_name, is_error and the other block fields; a message_delta's stop_details (the category of a streamed refusal) and container; context_management and input_transformations on the events; a compaction delta's encrypted_content and a thinking delta's estimated_tokens.lifecycle, line, deprecated_at and retires_at, the server_tools capability, xhigh effort, the disabled and between_tools thinking types, and the beta allowed_fallback_models and compaction capability.requestId, and toArray() includes request_id beside the type and message.meta() types the organization and workspace ID headers, retry-after and the fast mode rate limits; they also stay in custom.context_management.original_input_tokens as contextManagement.ping is still skipped.assertNotSent() accepts a number, like assertSent(), and ClientFake accepts a PSR-7 stream for content methods such as files()->download().final, so you can extend them; fake() on a subclass of a response builds from the parent's fixture.ErrorException with the API's error type instead of TransporterException.ErrorException (RateLimitException for a 429), even when the body isn't the API's JSON. A proxy's HTML page or a plain-text 503 used to throw UnserializableResponse or a TypeError, and files()->download() returned the error page as the file. The message is the first line of the page's text.toArray() with input as an ArrayObject, which encodes as {}: the API rejects a replayed "input": [].TypeError: a block that arrives whole with string content is read as a string.toArray().stop_sequence no longer raises a warning./ no longer doubles the slash in request paths.fake() overrides, a nested item whose type differs from the default's replaces it, so a faked tool_use block no longer carries the default text.completions() are marked deprecated: the API rejects /v1/complete requests on current models. Use the Messages API.Streams are read per the SSE spec, so a hand-written fake stream needs a blank line between events. UPGRADING.md lists the other changes that can affect code written against 1.8.
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.8.0...1.10.0
This release brings the response layer up to date with the Anthropic API changes shipped between April and July 2026: new usage fields, server-side fa
This release brings the response layer up to date with the Anthropic API changes shipped between April and July 2026: new usage fields, server-side fallback, compaction, and cache diagnostics.
Three additions to usage on Messages responses:
$response->usage->outputTokensDetails?->thinkingTokens; // how many billed output tokens were reasoning
$response->usage->speed; // 'fast' or 'standard' on fast mode requests
$response->usage->iterations; // per-attempt records under the fallback and compaction betas
When streaming, outputTokensDetails arrives on the final message_delta event.
When a refused request is retried on another model (the fallbacks parameter with the server-side-fallback-2026-07-01 beta header), the response now parses fully:
fallback content blocks mark the handoff: $block->from->model and $block->to->modelusage->iterations records every attempt: a message entry for a declined model, a fallback_message entry for the model that served the turnstop_details->recommended_model names a model to retry directly when the fallback itself was rate limitedstop_details->category now covers frontier_llm, reasoning_extraction, and general_harms alongside cyber and bioUnder the compact-2026-01-12 beta, responses can include a compaction content block whose content is a string summary. The SDK now handles that block, the compaction_delta stream event, the top-level context_management response field, and the stop_reason: 'compaction' value that appears with pause_after_compaction. All of it was verified against live API responses, including the quirk that iteration entries under this beta carry no model key.
foreach ($response->content as $block) {
if ($block->type === 'compaction') {
$block->content; // 'Summary of the conversation: ...'
}
}
$response->context_management; // ['applied_edits' => [...]] or null
With the cache-diagnosis-2026-04-07 header and a diagnostics request parameter, the API reports where two consecutive requests diverged:
$response->diagnostics?->cache_miss_reason?->type; // 'system_changed'
$response->diagnostics?->cache_miss_reason?->cache_missed_input_tokens; // 41850
On streams, diagnostics arrives on the message_start event.
The Messages, Thinking, Streaming, and Server Tools guides now cover refusal handling with fallback, compaction, cache diagnostics, thinking token usage, and the latest server tool versions (web_search_20260318, web_fetch_20260318, code_execution_20260521).
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.7.0...1.8.0
Upload a document once and reference it by file_id on later Messages calls. Useful for repeated PDFs and images, and for reading outputs produced by t
Upload a document once and reference it by file_id on later Messages calls. Useful for repeated PDFs and images, and for reading outputs produced by the code execution tool and Skills.
Five methods on $client->files():
upload(array $parameters): multipart upload, returns a FileResponselist(array $parameters = []): cursor-paginated listingretrieveMetadata(string $fileId): fetch metadata for a single filedownload(string $fileId): raw bytes for files produced by code execution or Skills (user-uploaded files are not downloadable)delete(string $fileId): returns a DeletedFileResponse$file = $client->files()->upload([
'file' => fopen('/path/to/doc.pdf', 'r'),
]);
$response = $client->messages()->create([
'model' => 'claude-opus-4-6',
'max_tokens' => 1024,
'betas' => ['files-api-2025-04-14'],
'messages' => [[
'role' => 'user',
'content' => [
['type' => 'text', 'text' => 'Summarise this.'],
['type' => 'document', 'source' => ['type' => 'file', 'file_id' => $file->id]],
],
]],
]);
Anthropic currently flags the Files endpoints as beta. The SDK auto-injects the required anthropic-beta: files-api-2025-04-14 header on every $client->files() call, so you don't type the version string. When you reference a file_id inside a Messages call, pass 'betas' => ['files-api-2025-04-14'] on that call too; the Messages endpoint also needs the header when a file is referenced.
New Files usage guide covers upload, list, retrieve, download, delete, and Messages integration, including the per-call betas pattern for referencing uploaded files.
Every Files response DTO has a fake() method for use with ClientFake:
FileResponse::fake()FileListResponse::fake()DeletedFileResponse::fake()Full Changelog: https://github.com/mozex/anthropic-php/compare/1.6.0...1.7.0
Add betas parameter for per-request beta feature opt-in by @mozex in https://github.com/mozex/anthropic-php/pull/16
betas parameter for per-request beta feature opt-in by @mozex in https://github.com/mozex/anthropic-php/pull/16Full Changelog: https://github.com/mozex/anthropic-php/compare/1.5.0...1.6.0
Full Changelog : 1.5.0...1.6.0
Add maxInputTokens and maxTokens properties to RetrieveResponse (and every item returned by ListResponse)
Models API
maxInputTokens and maxTokens properties to RetrieveResponse (and every item returned by ListResponse)capabilities tree on model responses: batch, citations, codeExecution, imageInput, pdfInput, structuredOutputs, thinking (with types.adaptive and types.enabled), and effort (with low, medium, high, max levels)capabilities.contextManagement as a map keyed by the raw API strategy name (clear_thinking_20251015, clear_tool_uses_20250919, compact_20260112, and any future version), so new strategies Anthropic ships are captured automatically without a package updateMessages API
stop_details on CreateResponse with type, category, and explanation — populated when stop_reason is 'refusal'caller on tool_use and server_tool_use content blocks (type and tool_id) so direct model calls can be distinguished from calls made inside a code execution sandboxcontainer_upload content block support with file_idinferenceGeo to CreateResponseUsage and CreateStreamedResponseUsage, surfacing which region handled the request ('us', 'eu', or null)pause_turn and refusal stop reasons and the idiom for resuming paused turnsMeta information
priorityInputTokenLimit and priorityOutputTokenLimit on MetaInformation, parsing the six anthropic-priority-* headers into typed properties instead of dropping them into the generic custom bucketDocumentation
platform.claude.com/docs/tool_use / server_tool_use toArray() output now includes the caller object when present, so response round-trips stay losslessMetaInformation rate-limit headers (including the new priority tier) round-trip cleanly through toArray()Full Changelog: https://github.com/mozex/anthropic-php/compare/1.4.0...1.5.0
Add adaptive thinking support (thinking.type: "adaptive") for Claude Opus 4.6 and Sonnet 4.6
thinking.type: "adaptive") for Claude Opus 4.6 and Sonnet 4.6display option on thinking config (summarized / omitted) to control thinking output in responsesoutput_config.effort parameter for guiding thinking depth (max, high, medium, low)server_tool_use content block type for server-side tools (web search, web fetch, code execution, tool search)web_search_tool_result content block type with search results arrayweb_fetch_tool_result content block typecode_execution_tool_result, bash_code_execution_tool_result, and text_editor_code_execution_tool_result content block typestool_search_tool_result content block typetool_use_id and content properties on CreateResponseContent for all server tool result blockscontainer field on CreateResponse for code execution sandbox persistencecitations array on text content blocks, supporting all 5 citation location types: char_location, page_location, content_block_location, web_search_result_location, search_result_locationcitations_delta streaming support with citation property on CreateStreamedResponseDeltawebFetchRequests, codeExecutionRequests, and toolSearchRequests to CreateResponseUsageServerToolUseserver_tool_use and server tool result blocks in CreateStreamedResponseContentBlockStartFull Changelog: https://github.com/mozex/anthropic-php/compare/1.3.3...1.4.0
updated model names for consistency
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.3.2...1.3.3
add batch response return type to client fake
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.3.1...1.3.2
Full Changelog : 1.3.1...1.3.2
Add dedicated inputTokenLimit and outputTokenLimit rate limit properties to MetaInformation
inputTokenLimit and outputTokenLimit rate limit properties to MetaInformationcache_creation breakdown to usage (CreateResponseUsageCacheCreation with ephemeral5mInputTokens and ephemeral1hInputTokens)serviceTier field to usage (standard, priority, or batch)serverToolUse field to usage (CreateResponseUsageServerToolUse with webSearchRequests)custom bucketFull Changelog: https://github.com/mozex/anthropic-php/compare/1.3.0...1.3.1
Add Message Batches support — create, retrieve, list, cancel, delete, and stream results
BatchResponse, BatchListResponse, DeletedBatchResponse, and BatchResultResponse response DTOsBatchIndividualResponse, BatchResult, and BatchResultError for parsing JSONL batch resultsBatchResponseRequestCounts for tracking processing, succeeded, errored, canceled, and expired countsBatchResultResponse::fake() for consumer testing with ClientFakeFull Changelog: https://github.com/mozex/anthropic-php/compare/1.2.3...1.3.0
BatchResponse, BatchListResponse, DeletedBatchResponse, and BatchResultResponse response DTOsBatchIndividualResponse, BatchResult, and BatchResultError for parsing JSONL batch resultsBatchResponseRequestCounts for tracking processing, succeeded, errored, canceled, and expired countsBatchResultResponse::fake() for consumer testing with ClientFakeinputTokenLimit and outputTokenLimit rate limit properties to MetaInformationcache_creation breakdown to usage (CreateResponseUsageCacheCreation with ephemeral5mInputTokens and ephemeral1hInputTokens)serviceTier field to usage (standard, priority, or batch)serverToolUse field to usage (CreateResponseUsageServerToolUse with webSearchRequests)custom bucketFull Changelog: https://github.com/mozex/anthropic-php/compare/1.2.3...1.3.0
add models list and retrieve support
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.2.2...1.2.3
add count tokens support
add models list and retrieve support
Full Changelog : 1.2.2...1.2.3
add anthropic-version header to the factory
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.2.1...1.2.2
added thinking support
add anthropic-version header to the factory
Full Changelog : 1.2.1...1.2.2
Add missing cache_creation_input_tokens and cache_read_input_tokens to CreateStreamedResponseUsage
cache_creation_input_tokens and cache_read_input_tokens to CreateStreamedResponseUsageFull Changelog: https://github.com/mozex/anthropic-php/compare/1.2.0...1.2.1
Full Changelog : 1.2.0...1.2.1
Add RateLimitException for HTTP 429 responses (extends ErrorException — no breaking changes)
RateLimitException for HTTP 429 responses (extends ErrorException — no breaking changes)ErrorException and UnserializableResponse via $e->responseMetaInformationCustom for capturing non-standard response headers via $meta->customOverrideStrategy enum for controlling fake() override merging behavioraddHeader() method to TransporterContract for runtime header injection(string) $response->getBody() instead of getContents() for reliable stream readingJSON_UNESCAPED_UNICODE flag for proper Unicode handling in request payloadsFakeable trait using array_replace_recursiveFakeable str_replace callStreamable trait methods for flexibilitySee UPGRADING.md for details. All changes are backwards compatible.
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.1.0...1.2.0
Add tool use (function calling) support by @mozex in https://github.com/mozex/anthropic-php/pull/6
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.0.3...1.1.0
Add tool use (function calling) support by @mozex in #6
Add cached tokens usage by @mozex in #7
Full Changelog : 1.0.3...1.1.0
add status code to error exceptions
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.0.2...1.0.3
bump dependencies
add php 8.4 to workflow
add status code to error exceptions
Full Changelog : 1.0.2...1.0.3
## What's Changed * Bump dependencies * Refactoring Full Changelog: https://github.com/mozex/anthropic-php/compare/1.0.1...1.0.2
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.0.1...1.0.2
Bump dependencies
Refactoring
Full Changelog : 1.0.1...1.0.2
- fix client fake types Full Changelog: https://github.com/mozex/anthropic-php/compare/1.0.0...1.0.1
Full Changelog: https://github.com/mozex/anthropic-php/compare/1.0.0...1.0.1
Initial Release
One column per month.