AI integration used to feel like a massive hurdle. You had to juggle API endpoints, handle weird JSON structures, and manage conversation state manually. Not anymore. With the Laravel AI SDK, building an AI chatbot is now a first-class experience in our favorite php web framework.
This tool brings elegance to AI development. It treats AI models like standard objects in your application. You don't need to be a prompt engineer to get started. You just need to be a developer who loves clean code.
The AI Push in Laravel
The ecosystem is evolving fast. Laravel 13 introduced the AI SDK as a core pillar for modern apps. It provides a unified API for OpenAI, Anthropic, and other major providers. You can swap models without changing your business logic.
This is the ultimate php developer tool for the AI era. It eliminates the boilerplate that usually slows down feature shipping. Whether you're building a simple support bot or a complex analysis tool, the foundation is already built for you.
Step 1: Install the SDK
The journey starts with a single command. You’ll need a fresh Laravel project or an existing one running version 13.

Open your terminal and run:
composer require laravel/ai
Once installed, publish the configuration file. This gives you control over your default providers and model settings.
php artisan vendor:publish --tag="ai-config"
Now, add your API keys to your .env file. The SDK supports multiple providers out of the box.
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-...
The configuration is straightforward. You define which model to use for specific tasks. This flexibility is a core part of the Laravel philosophy.
Step 2: Define Your Agent
In the Laravel AI SDK, an Agent is a class that encapsulates AI logic. Think of it as a Controller for your AI interactions. It holds the instructions, tools, and the desired output format.

You can scaffold an agent using Artisan:
php artisan make:ai-agent SupportChatbot
This creates a new file in app/Ai/Agents. Here is where you define the "brain" of your chatbot. You must implement the instructions() method. This tells the AI how to behave.
namespace App\Ai\Agents;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Promptable;
use Stringable;
class SupportChatbot implements Agent
{
use Promptable;
public function instructions(): Stringable|string
{
return 'You are a helpful customer support agent for a shoe store.
Answer questions about shipping, sizing, and returns.
Be polite and concise.';
}
}
The Promptable trait is where the magic happens. It gives your class the ability to send and receive messages from the AI provider seamlessly.
Step 3: Build the API Endpoint
Now you need a way for your frontend to talk to this agent. You can build rest api with php using Laravel's simple routing system.
Open routes/web.php or routes/api.php. Create a POST route that accepts a user message.
use App\Ai\Agents\SupportChatbot;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::post('/chat', function (Request $request) {
$message = $request->input('message');
$response = SupportChatbot::make()
->prompt($message);
return response()->json([
'reply' => $response->content(),
]);
});
This code does three things. It initializes the agent. It sends the user's input. It returns the AI's response as a JSON object. You have a functional chatbot backend in under ten lines of code.
Step 4: Structured Output for Better Data
A text response is great for users. But sometimes your application needs data it can actually use. The SDK makes this easy with HasStructuredOutput.
You can define a JSON schema for the response. This ensures the AI always returns the same format.
use Laravel\Ai\Contracts\HasStructuredOutput;
use Illuminate\Contracts\JsonSchema\JsonSchema;
class SupportChatbot implements Agent, HasStructuredOutput
{
public function schema(): JsonSchema
{
return JsonSchema::from([
'type' => 'object',
'properties' => [
'reply' => ['type' => 'string'],
'sentiment' => ['type' => 'string', 'enum' => ['happy', 'angry', 'neutral']],
'category' => ['type' => 'string'],
],
'required' => ['reply', 'sentiment'],
]);
}
}
Now, when you call the agent, you get more than just a reply. You get insights. Your app can flag "angry" customers for human review automatically. This moves beyond simple chat and into intelligent automation.
Real World Integration
The SDK isn't just for small demos. It’s designed for heavy lifting in production environments. You can integrate these agents directly into your admin panels or customer dashboards.

In the screenshot above, you can see how AI-driven features assist with content generation and social media management. This is the power of bringing AI inside your framework. You don't have to leave your familiar Laravel documentation to build something world-class.
Step 5: Conversations and Memory
A chatbot that forgets who you are isn't very useful. The Laravel AI SDK includes conversation persistence. It uses your database to store message history.
To enable this, implement the Conversational interface. The SDK handles the rest. It will automatically inject the last few messages into the prompt so the AI has context.
use Laravel\Ai\Contracts\Conversational;
class SupportChatbot implements Agent, Conversational
{
// Memory is handled automatically by the SDK's database driver.
}
This allows for complex multi-turn dialogues. Your users can ask follow-up questions just like they would in ChatGPT.
Shipping Your Chatbot
Development is only half the battle. You need to get your code into the hands of users. Laravel offers several ways to deploy your AI-powered apps.

For a managed experience, Laravel Cloud is the gold standard. It handles the infrastructure so you can focus on the AI logic. If you prefer managing your own servers, Forge makes provisioning effortless.
The combination of the AI SDK and these deployment tools creates a massive advantage. You can go from an empty folder to a live AI product in a single afternoon.
Conclusion
The barriers to entry for AI have collapsed. Laravel has carved out a path that prioritizes developer joy and rapid shipping. You no longer need to fear the complexity of LLMs.
By using Agents, structured output, and built-in memory, you can build sophisticated features today. Beginners, builders, and seasoned pros can all find value here. Start with a chatbot. Then, dig into vector search and RAG.
The future of web development is intelligent. Your next great application starts with composer require laravel/ai. We'd love to hear what you build with it.