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

Sdk Laravel Package

anthropic-ai/sdk

A PHP SDK for the Anthropic API that lets you call Claude models from Laravel or plain PHP apps, with support for streaming responses, tool use, vision inputs, and typed message building for adding AI features quickly.

View on GitHub
Deep Wiki
Context7

anthropic-ai/sdk is a PHP client for Anthropic's Claude API, giving Laravel and standalone PHP applications a clean, typed interface to large language models. It handles HTTP transport, authentication, and error handling so you can focus on building AI-powered features instead of wiring requests by hand.

  • Messages API — send multi-turn conversations with system prompts using typed request and response objects.
  • Streaming — consume Claude's replies token-by-token for real-time, incremental output.
  • Tool use — define tools and parse structured tool-call responses.
  • Configurable transport — swap in any PSR-compatible HTTP client, with sensible timeouts and retries.
  • Framework-friendly — runs standalone or alongside Laravel's container and configuration.
Frequently asked questions about Sdk
How do I install the Anthropic PHP SDK in a Laravel application?
Install it with a single composer require anthropic-ai/sdk command; there are no native extensions, daemons, or database migrations involved. Because the package ships without a Laravel service provider or auto-discovery, you register the client yourself, typically as a singleton in AppServiceProvider or a dedicated AnthropicServiceProvider. Pull the API key from config/services.php backed by an environment variable, and expose model, max tokens, timeout, and retry policy as config keys. Time-to-first-call is usually a few minutes for a developer who already has an API key.
Does the anthropic-ai/sdk work with Laravel 10 and Laravel 11?
The SDK is framework-agnostic and built on a PSR-18 HTTP client, so it does not depend on a specific Laravel version. Laravel ships Guzzle, which satisfies the transport requirement with effectively zero setup, and proxy, CA bundle, and timeout settings propagate normally. The real constraint is the package's PHP version floor, so check its composer.json constraint against every runtime in your fleet, including your oldest supported service, before committing.
Do I need a service provider or facade to use the Anthropic SDK in Laravel?
No, because this is a vendor SDK rather than a Laravel package: there is no bundled service provider, facade, or publishable config. You own the glue code, which realistically means a singleton binding, config entries in config/services.php, and optionally a facade or typed wrapper for ergonomics. Budget roughly a day of wrapper work to make it feel idiomatic inside a Laravel codebase.
How should I store and configure the Anthropic API key in a Laravel app?
Start with an environment variable referenced from config/services.php so the value works with config caching, and use a secrets manager or Laravel's encrypted config for stricter environments. Authentication is a bearer API key, so per-tenant key routing is possible but must be built yourself rather than configured. Prompts and completions leave your infrastructure, so get data residency, PII handling, and retention sign-off before production regardless of how the key is stored.
How do I stream Claude responses in Laravel with this SDK?
The SDK supports server-sent event streaming, but streaming does not fit a standard Laravel request/response cycle or Blade rendering. You need a dedicated streaming controller using StreamedResponse or an SSE or websocket channel, with output buffering disabled. Design that seam up front, and consider whether streaming is needed for v1 at all or whether request/response is enough to ship.
Can I call Claude from a Laravel queue job instead of during a request?
Yes, and queueing is the safer default for anything with meaningful latency, such as batch summarization, document processing, or agentic jobs. The SDK supports both synchronous in-request calls and queued work, but in-request use should be reserved for fast chat completions, classification, or extraction within your p95 latency budget. Configure timeouts and a retry policy with backoff and jitter, and cap queue concurrency so a runaway job cannot generate a large bill.
Is there a Laravel-native alternative to the anthropic-ai/sdk package?
There is no first-party Laravel package from Anthropic, so community wrappers exist but add another abstraction layer over the same HTTP API. Because this SDK is thin and framework-agnostic, most teams use it directly behind their own internal LlmClient interface, which keeps the vendor SDK as one adapter instead of a pervasive dependency. That interface also makes it cheaper to switch providers later, since migrating means rewriting prompt logic, tool schemas, and response parsing.
How do I test Laravel code that calls the Anthropic API?
Do not hit the live API in your test suite. Put an internal interface in front of the SDK, bind a fake or stub implementation in the container for feature tests, and use recorded fixtures or a mock PSR-18 handler for integration-level coverage of request and response parsing. Test streaming controllers separately, since they exercise a different code path than normal JSON responses.
Is the Anthropic PHP SDK mature enough for production use?
It is vendor-official but has limited third-party validation, with roughly 191 stars and no dependents, which means you would be an early adopter and should expect some undocumented edge cases. Pin exact versions, read changelogs carefully, and verify the actual release cadence on GitHub and Packagist, since the recorded last-release date appears anomalous and should be confirmed directly. Wrapping the SDK behind your own interface limits the blast radius of a breaking minor release.
How do I handle errors, retries, and cost control with the Anthropic SDK in Laravel?
Set an explicit timeout and a retry policy with exponential backoff and jitter, cap the number of attempts, and catch transport exceptions from the underlying PSR-18 client so failures degrade gracefully. Log request metadata and token usage so you can spot runaway spend early, and consider a circuit breaker around the client. Rate-limit blast radius is an operational risk rather than an architectural one, but it is the failure mode most likely to reach a finance conversation.
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.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager