- How do I install **mozex/anthropic-php** in a Laravel project?
- Run `composer require mozex/anthropic-php` for the base SDK. For Laravel-specific features (Service Container, config, facade), add `mozex/anthropic-laravel` via `composer require mozex/anthropic-laravel`. The Laravel wrapper auto-registers with your app’s container.
- Does this package support Laravel’s built-in HTTP client (Guzzle)?
- Yes. The package is PSR-18 compliant and works seamlessly with Laravel’s default Guzzle client (`illuminate/http-guzzle-promise`). No additional setup is required for basic usage.
- Can I use custom HTTP clients like Symfony’s HttpClient instead of Guzzle?
- Absolutely. The SDK uses `php-http/discovery` to auto-install a PSR-18 client, but you can override it by binding your preferred client (e.g., Symfony) in Laravel’s Service Container.
- What Laravel versions does **mozex/anthropic-laravel** support?
- The package supports Laravel 10.x and 11.x. Check the [mozex/anthropic-laravel GitHub](https://github.com/mozex/anthropic-laravel) for version-specific requirements and compatibility notes.
- How do I handle streaming responses in Laravel for real-time chat apps?
- Use the `stream()` method on responses, which returns an iterator. In Laravel, you can dispatch events or queue jobs for each chunk using `bus:dispatch` or `queue:listen`. Example: `foreach ($response->stream() as $chunk) { event(new ChatUpdate($chunk)); }`.
- Does the SDK support Anthropic’s tool use feature (function calling)?
- Yes. The SDK fully supports tool use, including server tools for executing functions (e.g., calling external APIs or database queries). Tools are defined as arrays in your message payload, and the SDK handles the `tool_use` response format automatically.
- How do I test my Laravel app without hitting Anthropic’s API?
- Use the `ClientFake` utility provided by the package. It mocks HTTP requests and responses, allowing you to test all features (messages, streaming, tools) locally. Example: `$client = new ClientFake(); $anthropic = new Anthropic($client);`.
- Are there any known issues with rate limiting in production?
- The SDK includes `$response->meta()` to access rate limit headers (e.g., `rate_limit_remaining`). For production, implement exponential backoff or queue retries using Laravel’s `queue:after` events to handle throttling gracefully.
- What are the alternatives to **mozex/anthropic-php** for Laravel?
- For Anthropic, this is the most feature-complete PHP SDK. Alternatives include writing a custom HTTP client or using a generic PSR-18 wrapper, but they lack Laravel-specific integrations (e.g., config, facade) or advanced features like tool use or streaming helpers.
- How do I configure the Laravel wrapper to use a custom API key per environment?
- Add your API key to `.env` as `ANTHROPIC_API_KEY`. The Laravel wrapper reads this automatically. For multi-environment setups, use Laravel’s config caching (`php artisan config:cache`) or environment-specific `.env` files.