AI isn't a future-tense feature anymore. It's the current standard for modern applications.
For years, PHP developers had to glue together disparate APIs to build intelligent features. You managed multiple client libraries and handled inconsistent response formats. Those days ended with the Laravel AI SDK.
Laravel has evolved into the definitive php web framework for the AI era. It provides a first-party, unified interface for OpenAI, Anthropic, Gemini, and more. You don't just "add AI" to a Laravel app. You build AI-native experiences that ship faster and perform better.
This guide covers everything you need to dominate AI development using the latest php developer tools.
Laravel AI SDK: The Foundation
The Laravel AI SDK is more than a simple wrapper. It is a robust engine designed for rapid feature delivery. It solves the fragmentation problem by offering a single, expressive API.
You configure your providers once in config/ai.php. Switching from OpenAI to Anthropic is a single line change. The framework handles the heavy lifting, from authentication to error handling.

This integration allows you to build sophisticated tools like automated content assistants. In the image above, the backend uses the SDK to suggest titles and generate social media posts automatically. This is how you build rest api with php that actually helps the user.
Creating Your First Agent
The "Agent" is the heart of Laravel's AI strategy. Instead of scattered function calls, you define AI logic within dedicated PHP classes.
An Agent encapsulates everything:
- Instructions: Define the model's persona and rules.
- Tools: Give the agent access to your database or external APIs.
- Memory: Let the agent remember previous conversation context.
- Structured Output: Force the model to return typed data or JSON.
namespace App\AI\Agents;
use Laravel\AI\Agents\Agent;
class SupportAgent extends Agent
{
protected string $instructions = 'You are a helpful support bot for our SaaS platform.';
protected array $outputSchema = [
'status' => 'string',
'resolution' => 'string',
];
}
This approach brings the same elegance to AI that Eloquent brought to databases. It’s clean, testable, and deeply integrated into the Laravel lifecycle.
Semantic Search & RAG
Traditional keyword search is dying. Users want to find information based on meaning, not just exact word matches. This is where Retrieval-Augmented Generation (RAG) shines.
Laravel makes vector search accessible. You can generate embeddings directly from strings using built-in methods. These vectors represent the "essence" of your data.
- Embed: Convert your text into a vector using OpenAI or Cohere.
-
Store: Save the vector in Postgres using
pgvector. - Retrieve: Use similarity search to find the most relevant context.
- Answer: Feed that context to your Agent to provide accurate answers.

Laravel’s Query Builder now supports vector comparison out of the box. You can build a context-aware knowledge base without leaving the ecosystem you love.
Real-world Workflows: Streaming & Queuing
AI models can be slow. A 10-second wait for a response ruins the user experience. Laravel solves this with native support for streaming and queuing.
Streaming for Instant Feedback
Use the stream method to send tokens to the frontend as they are generated. When paired with Livewire or Inertia, the UI updates in real-time. The user sees the answer being typed out, creating a high-performance feel.
Queuing for Background Jobs
Generating a 2,000-word report shouldn't block a web request. Use the queue method to offload the work to a background worker.
$agent->queue('Analyze last months sales data', function ($result) {
// Notify the user via a broadcast or email
});
This keeps your application snappy while performing complex reasoning in the background.
The Full Ecosystem Stack
Shipping an AI app is about more than just code. You need infrastructure that can handle the load. The Laravel ecosystem provides a complete vertical slice.

- Laravel Cloud: Managed infrastructure that scales automatically.
- Forge: Painless server management for custom deployments.
- Nightwatch: Real-time monitoring and logs for your AI agents.
By using these tools, you avoid reinventing the wheel. You focus on building features, while the ecosystem handles deployment and monitoring.
Why Laravel for AI?
The choice of a web framework determines your velocity. Laravel offers the best-in-class developer experience for AI.
- Elegant Syntax: Write code that reads like a sentence.
- Rapid Shipping: Move from idea to production in days, not months.
- Joyful Development: Tools like Laravel Boost and the AI SDK remove the friction of modern web dev.
Whether you are an indie maker or part of an enterprise team, the goal is the same. You want to ship intelligent features that users love.
Moving Forward
The AI landscape changes every week. Models get faster, and new providers emerge. Laravel’s abstraction layer protects you from this volatility.
Beginners, builders, and behind-the-scenes folks: everyone has a place here. The tools are ready. The documentation is clear. Your next AI-powered project starts with composer require laravel/ai.
We’d love to hear what you’re building. Share your AI-powered Laravel apps with the community and help us shape the next wave of web development.