Getting Started with PrismPHP: A Beginner's Guide to AI-Powered Laravel Applications

Author

Kritim Yantra

May 07, 2025

Getting Started with PrismPHP: A Beginner's Guide to AI-Powered Laravel Applications

Artificial Intelligence is transforming how we build web applications. With the rise of Large Language Models (LLMs) like OpenAI’s GPT, Anthropic’s Claude, and Mistral, developers can now integrate powerful AI features into their apps effortlessly. That’s where PrismPHP comes in—a Laravel package designed to simplify and supercharge your LLM integrations.

In this beginner-friendly blog post, we'll explore what PrismPHP is, why it’s useful, and how you can start using it in your Laravel projects.


🔍 What is PrismPHP?

PrismPHP is a modern Laravel package that provides a unified, fluent interface for working with LLMs. Instead of juggling multiple SDKs and API formats, PrismPHP lets you focus on what matters—building smart features—while handling all the messy details behind the scenes.

Whether you want to build a chatbot, generate content, analyze documents, or use AI for structured data, PrismPHP gives you a clean, expressive Laravel-style syntax to do it all.


🚀 Key Features

✨ Elegant Provider Integrations

Out of the box, PrismPHP supports popular providers like OpenAI, Anthropic, Mistral, Ollama, and more. Switching between providers is as simple as changing a method.

✍️ Fluent Text Generation

Generate text using a chainable API similar to Laravel’s Facades. It's intuitive, clean, and fun to use.

⏳ Real-time Streaming Output

PrismPHP allows you to stream model responses in real time—ideal for long-form answers or live chat interfaces.

🧑💼 Tool & Function Calling

Define custom tools (like database lookups or API calls) that LLMs can invoke on-the-fly during conversation.

📄 Structured Output Handling

Ensure your AI responses match specific formats using schema validation and structured response parsing.

📷 Multi-modal Support

Incorporate images and documents seamlessly, thanks to support for vision tasks and document analysis.

🌐 Prism Server

Expose your AI models via an OpenAI-compatible API using Prism Server—perfect for building your own internal LLM-based services.

✅ First-class Testing Support

Use built-in testing tools to fake responses and simulate AI behavior without hitting live APIs.


📄 Installation & Setup

Requirements

  • PHP 8.2+
  • Laravel 11+

→ Step 1: Install PrismPHP

composer require prism-php/prism

→ Step 2: Publish Configuration

php artisan vendor:publish --tag=prism-config

This will create a config/prism.php file where you can customize settings and provider credentials.


💡 Basic Usage Example

use Prism\Prism\Prism;
use Prism\Prism\Enums\Provider;

$response = Prism::text()
    ->using(Provider::Anthropic, 'claude-3-sonnet')
    ->withSystemPrompt(view('prompts.system'))
    ->withPrompt('Explain quantum computing in simple terms.')
    ->asText();

echo $response->text;

That’s it! You’ve just used an advanced LLM to generate a simple explanation using clean, readable code.


🚀 Advanced Features

📈 Embeddings & Structured Schemas

Use embeddings for similarity search and schema-based outputs for consistent data formats.

🛠️ Custom Providers

Integrate with any other LLM provider by implementing Prism’s Provider contract.

🚀 Prism Server API

Turn your Prism-powered app into an API service that mimics OpenAI’s endpoints. Great for internal tools and extensions.


📖 Conclusion

PrismPHP is the Laravel-native toolkit you need to bring AI power into your web applications. It combines the flexibility of multi-provider support with Laravel’s elegance and developer-friendly syntax.

Whether you’re building an AI assistant, a content generator, or a smart internal dashboard, PrismPHP makes it easy and enjoyable.

So why wait? Install PrismPHP today and start building the future with Laravel and AI.

Tags

Comments

No comments yet. Be the first to comment!

Please log in to post a comment:

Sign in with Google

Related Posts