mozex/anthropic-php
Community-maintained PHP SDK for the Anthropic API. Send messages, stream responses, call tools, use extended thinking, web search, code execution, files, and batches. PSR-18 compatible, works with any HTTP client; Laravel wrapper available.
Illuminate\Http\Client). This ensures seamless integration with Laravel’s existing HTTP infrastructure.mozex/anthropic-laravel package provides Service Container integration, config-based setup, and a facade, reducing boilerplate for Laravel applications.readonly objects with IDE autocompletion, improving developer experience and reducing runtime errors.Anthropic::client('API_KEY')), while the Laravel wrapper reduces this further.php-http/discovery to auto-install a PSR-18 client (e.g., Guzzle), but allows customization (e.g., Symfony HTTP Client).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| API Changes | Anthropic’s API evolves rapidly; SDK must stay updated. | Package uses forward-compatible design (parameters pass through to API unchanged). |
| PSR-18 Dependency | Requires a PSR-18 client (e.g., Guzzle). | Laravel already includes illuminate/http-guzzle-promise; no additional setup needed. |
| Rate Limits | Anthropic enforces strict rate limits. | SDK includes $response->meta() for real-time limit tracking. |
| Beta Features | Files API and other betas may change. | SDK auto-injects required headers (e.g., anthropic-beta: files-api-2025-04-14). |
| Error Handling | Custom error responses may require handling. | Well-documented error handling. |
mozex/anthropic-laravel) be adopted for Service Container benefits?ClientFake testing utility reduce reliance on external API calls in CI?mozex/anthropic-laravel package provides:
Anthropic::messages()->create()).illuminate/http-guzzle-promise).bus:dispatch for real-time updates).| Step | Action | Tools/Libraries Used |
|---|---|---|
| 1. Evaluation | Test core features (messages, streaming) in a sandbox. | mozex/anthropic-php + ClientFake |
| 2. Laravel Integration | Adopt mozex/anthropic-laravel for Service Container setup. |
Composer, Laravel Service Provider |
| 3. Feature Rollout | Phase in advanced features (tools, files, batches) based on priority. | Feature flags, config-based enablement |
| 4. Testing | Replace mock HTTP servers with ClientFake for unit tests. |
PHPUnit, Pest |
| 5. Monitoring | Instrument $response->meta() for rate limit tracking. |
Laravel Observers, Sentry |
| 6. Scaling | Implement queue-based retries for rate-limited requests. | Laravel Queues, spatie/laravel-queue-retries |
readonly classes.illuminate/http-guzzle-promise.Anthropic::messages()->create().$response->usage for cost tracking.ClientFake for faster tests.mozex/anthropic-php (or mozex/anthropic-laravel) and a PSR-18 client.$response->errors().Log::debug($response->meta())).$response->meta() provides remaining limits and reset times.$client->batches().$response->usage logs input/output tokens.$client->models()->list() to pick cost-effective models.| Failure Scenario | Impact | Mitigation Strategy |
|---|---|---|
| API Downtime | No responses from Anthropic. | Implement fallback to cached responses or queue retries. |
| **Rate Limit Ex |
How can I help you explore Laravel packages today?