- How do I install Prism in a Laravel project?
- Run `composer require prism-php/prism` in your project directory. Prism requires Laravel 11+ and PHP 8.2+. After installation, publish the config file with `php artisan vendor:publish --tag=prism-config` and set your API keys in `.env`.
- Which AI providers does Prism support out of the box?
- Prism supports OpenAI, Anthropic, and other providers via a unified interface. You can switch providers dynamically at runtime using methods like `Prism::text()->using(Provider::OpenAI)`. Additional providers can be added via custom adapters.
- Can Prism handle multi-step conversations like chatbots?
- Yes, Prism includes built-in support for multi-step conversations. You can maintain conversation state using `Prism::conversation()` and chain messages sequentially. For persistence, store the conversation history in a database or cache layer.
- How do I integrate custom tools or functions with LLM responses?
- Use the `Prism::text()->withTools()` method to define functions the LLM can call. Tools are mapped to PHP closures or controller methods, enabling dynamic interactions like database queries or external API calls. Example: `->withTools([new DatabaseQueryTool()])`.
- What Laravel versions does Prism support?
- Prism is designed for Laravel 11+ and requires PHP 8.2+. It leverages Laravel’s service container, Facades, and caching, so older versions (e.g., Laravel 10) are not supported. Check the [Prism website](https://prismphp.com) for version-specific updates.
- How do I secure API keys for multiple providers?
- Store API keys in Laravel’s `.env` file (e.g., `ANTHROPIC_API_KEY=...`). Prism retrieves them via the service container. For production, use Laravel Forge, Vault, or a secrets manager. Never hardcode keys in your application.
- Can I use Prism for async LLM operations to avoid timeouts?
- Yes, dispatch LLM requests asynchronously using Laravel queues. Wrap Prism calls in a job (e.g., `PrismJob::dispatch()`) and process responses later. Configure `request_timeout` in `config/prism.php` to handle long-running operations.
- What’s the best way to test Prism in a CI/CD pipeline?
- Mock LLM responses using Laravel’s HTTP testing helpers or a library like `mockery`. Test conversation flows with `Prism::conversation()->assertResponse()`. For provider-specific tests, use mock adapters or stubbed API responses to avoid rate limits.
- How do I handle rate limits or cost spikes with Prism?
- Monitor usage with Laravel’s `throttle` middleware or a package like `spatie/rate-limiting`. Implement budget alerts via Laravel Notifications or a dashboard. Prism supports runtime provider switching, so you can fallback to a cheaper provider if needed.
- Are there alternatives to Prism for LLM integration in Laravel?
- Alternatives include `laravel-ai` (official Laravel AI tools) or `php-ai` for general-purpose LLM wrappers. Prism stands out for its fluent API, multi-provider support, and built-in tool/function calling. Choose based on your need for abstraction (Prism) vs. flexibility (raw API clients).