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

Prism Laravel Package

prism-php/prism

Prism is a Laravel package for integrating LLMs into your apps with a fluent interface for text generation, multi-step conversations, and tool use across multiple AI providers, so you can build AI features without wrestling with provider intricacies.

View on GitHub
Deep Wiki
Context7

Prism is a powerful Laravel package for integrating Large Language Models (LLMs) into your applications. It offers a fluent, expressive interface for generating text, managing multi-step conversations, and leveraging tools across multiple AI providers—so you can focus on building outstanding AI features without wrestling with provider-specific intricacies.

  • Seamless integration with popular LLM providers
  • Fluent API for text generation and chat workflows
  • Built-in support for multi-step conversations
  • Tool calling for agentic, function-driven apps
  • Configurable, Laravel-native architecture
Frequently asked questions about Prism
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.
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.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log