DEV Community

PHP CMS Framework
PHP CMS Framework

Posted on

Laravel and Prism PHP: The Modern Way to Work with AI Models

Every Laravel project that needs AI ends up with a different implementation. One project uses the OpenAI PHP client directly. Another one uses a wrapper someone wrote three years ago that is no longer maintained. A third one is tightly coupled to a specific model, so switching from GPT-4o to Claude requires rewriting half the service layer.

Prism PHP solves this properly. It is a Laravel package that gives you a single, consistent API for working with multiple AI providers. OpenAI, Anthropic Claude, Ollama for local models, Mistral, Gemini, and more, all through the same fluent interface. You switch providers by changing one line. Your application code does not care which model is behind it.

This post covers the full picture. All the supported providers and when to use each one, text generation with structured output, tool calling so your AI can actually interact with your application, and embeddings for semantic search. I will tie all three together with a real-world example at the end so you can see how they work as a system rather than isolated features.

What you need:

Laravel 10 or 11
PHP 8.1+
Composer
API keys for whichever providers you plan to use.
Ollama requires a local install but is free to run.

For more details - https://www.phpcmsframework.com/2026/04/laravel-prism-php-ai-models.html

Top comments (0)