- How do I install Prism in a Laravel 11+ project?
- Run `composer require prism-php/prism` and publish the config with `php artisan prism:install`. The package auto-discovers providers like OpenAI and Anthropic via your `.env` keys (e.g., `OPENAI_API_KEY`). Ensure PHP 8.1+ and Laravel 10+ are installed first.
- Which LLM providers does Prism support out of the box?
- Prism supports OpenAI, Anthropic, Mistral, Gemini, and others via provider adapters. Each provider’s features (e.g., tool use, streaming) depend on its API capabilities. Check the [official docs](https://prismphp.com) for a full list and version requirements.
- Can I use Prism for real-time chat applications with streaming responses?
- Yes, Prism supports streaming via `StreamEvent` listeners. Use the `stream()` method on a chat or completion call, then handle events in your event queue. Note that consumers must parse `data-artifact` payloads for structured streaming data.
- How does Prism handle tool calling and function execution?
- Define tools as JSON schemas in your config, then call them via `->withTools()` on a chat or completion request. Prism validates inputs/outputs against schemas and executes tools asynchronously via Laravel queues. Retries and fallbacks require custom event handlers.
- What’s the best way to cache LLM responses in Prism?
- Prism integrates with Laravel’s cache (Redis/Memcached) for responses. Enable caching per provider in `config/prism.php` and use tags like `prism:anthropic:completion` for granular invalidation. Some providers (e.g., Anthropic) have built-in caching.
- Does Prism work with Laravel’s queue system for async LLM calls?
- Yes, Prism dispatches tool calls and long-running operations to Laravel queues by default. Configure your queue worker (`php artisan queue:work`) to handle async LLM tasks. Monitor queue jobs for timeouts or retries in production.
- How do I migrate from Prism v0.99.x to v0.100.0’s structured output mode?
- Update your tool schemas to use `structured_output` mode and ensure your event listeners handle the new `ToolResultEvent` format. Run `php artisan prism:migrate` if available, then test with mock providers in staging to catch schema validation errors.
- Are there alternatives to Prism for Laravel LLM integration?
- Alternatives include `laravel-ai` (simpler, less feature-rich) and direct SDKs (e.g., OpenAI’s PHP SDK). Prism stands out for multi-provider abstraction, tool orchestration, and Laravel-native integrations like queues and caching. Choose Prism if you need cross-provider flexibility.
- How do I test Prism in a CI pipeline with mocked LLM responses?
- Use Prism’s mock providers (e.g., `MockProvider`) in your tests. Configure them in `config/prism.php` and assert responses with PHPUnit/Pest. Example: `Prism::mock('openai')->shouldReturn('test response');` for predictable testing.
- What are the performance implications of using Prism’s abstraction layer?
- Prism adds ~10–20ms overhead per call due to validation, event dispatching, and provider routing. Benchmark in staging with your target LLM (e.g., OpenAI’s `gpt-4`). For low-latency needs, consider direct SDK calls or caching aggressive responses.