Weave Code
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 with a fluent API. Generate text, run multi-step conversations, and call tools across multiple AI providers, so you can build AI features in your app without wrestling with provider-specific details.

View on GitHub
Deep Wiki
Context7

A unified interface for working with LLMs in Laravel

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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata