Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Anthropic Php

Anthropic Php Laravel Package

mozex/anthropic-php

Community-maintained PHP SDK for the Anthropic API: send messages, stream responses, call tools, use extended thinking, web search, code execution, batches, and files. Works with any PSR-18 HTTP client, plus a Laravel wrapper. Full docs at mozex.dev.

View on GitHub
Deep Wiki
Context7

Anthropic PHP is a community-maintained PHP SDK for the Anthropic API, giving you a clean, typed interface to Claude models without tying you to a framework. It works with any PSR-18 HTTP client, so it drops easily into existing PHP projects, and a companion Anthropic Laravel package adds service container integration, config-based setup, and a facade for Laravel users.

  • Send messages and stream responses token by token
  • Define tools and let Claude call them, with extended thinking support
  • Use server tools like web search and code execution
  • Handle citations, token counting, and model listings
  • Run batches, upload files, and access legacy completions
Frequently asked questions about Anthropic Php
How do I install mozex/anthropic-php in a Laravel application?
Install it with Composer using composer require mozex/anthropic-php. The package requires PHP 8.2 or newer, and php-http/discovery will auto-install a PSR-18 HTTP client if your project does not already have one. Once installed, you create a client with Anthropic::client($apiKey) and call resources such as messages(), files(), or batches(). In Laravel you would typically bind that client as a singleton in a service provider and inject it into a dedicated AI service class.
Does this Anthropic PHP SDK support Laravel 11 and Laravel 12?
Yes. The SDK needs PHP 8.2+, which lines up with the Laravel 11 and 12 estate, so it drops in without version conflicts. Legacy Laravel 9 and 10 projects are blocked unless they upgrade PHP, so plan for that if you maintain older apps. There is also a companion mozex/anthropic-laravel wrapper that adds config-based setup, service container integration, and a facade if you prefer a Laravel-native feel.
Can I use my existing Guzzle or Symfony HTTP client with this package?
Yes. The SDK is PSR-18 based, so you can inject any compatible client via Anthropic::factory()->withHttpClient($client). That means your existing organization-wide HTTP policy, including proxy settings, timeouts, TLS configuration, and tracing middleware, carries over instead of being reimplemented inside the SDK. If no client is supplied, php-http/discovery finds one automatically.
How do I test Laravel code that calls the Anthropic API without making real API requests?
The package ships its own ClientFake, which records requests and exposes assertSent() so you can assert exactly what payloads your application built. That lets CI run AI-touching paths deterministically with no live API calls, no token spend, and no flaky network failures. Combine it with dependency injection so your service class receives the faked client rather than constructing one inline.
How do I stream Claude responses in PHP with this SDK?
Streaming is a first-class feature: call the messages resource with streaming enabled and consume the event stream as it arrives. The usual production failure point is not the SDK but your delivery path, so check PHP-FPM plus nginx output buffering and default timeouts, or route the stream through Octane, an SSE endpoint, or a queue-backed job. Test the buffering behavior end to end before shipping.
Does the SDK support tool use, extended thinking, web search, and code execution?
Yes. Messages, tool use, extended thinking, server tools such as web search and code execution, citations, batches, files, and token counting are all documented and supported. Parameters are passed through to the Anthropic API as-is, so newly shipped Anthropic features, including new tool types, thinking modes, and beta headers, are reachable the day Anthropic releases them without waiting for an SDK update. That pass-through design is the strongest reason to adopt this client in a fast-moving vendor category.
Should I install mozex/anthropic-php or mozex/anthropic-laravel?
Install mozex/anthropic-laravel if you want the fastest path: config-driven credentials, a facade, and container integration out of the box. Depend on mozex/anthropic-php alone and register your own singleton bound to an internal AiClient interface if you want fewer dependencies to vet, which is the safer choice for customer-facing code. Either way, keep SDK calls inside a dedicated service class rather than controllers or Blade templates.
Is this package safe for production given it is community-maintained?
It is a thin, PSR-18 transport client maintained by a single developer with a modest star count, so treat community validation as limited and pin versions. The upside is that the abstraction is thin enough that the exit cost to raw Guzzle is measured in days, not months, especially if you keep the client behind an internal interface. Also note the Files API is explicitly beta and requires an anthropic-beta header, so gate beta surfaces behind feature flags and avoid making them load-bearing.
How do I count tokens and read rate limits with this PHP Anthropic client?
The SDK exposes a token counting endpoint before you send a request and returns usage token counts on responses, plus rate-limit metadata through meta(). It does not provide metering or per-tenant cost attribution, so instrument those yourself if you need billing or budget enforcement. Typed response DTOs can lag newly added API fields, so read the changelog on upgrades and budget time for occasional drift.
How does this compare to Prism, Laravel AI, or a homegrown provider layer?
Prism, Laravel AI, and in-house provider layers are multi-provider abstractions, whereas this package is a thin Anthropic-specific transport client with array parameters and typed DTOs. If multi-provider portability is a near-term requirement, put this SDK behind an internal interface rather than replacing an abstraction you already have, which also avoids duplicating a competing layer in your estate. If you only need Anthropic and want immediate access to new API features, the direct client is simpler and easier to swap out later.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums