Modern applications are no longer just CRUD systems—they’re intelligent, conversational, and adaptive. With Laravel 12, the framework officially stepped into the AI era by introducing the Laravel AI SDK, a first-class, elegant solution for integrating artificial intelligence into Laravel applications.
The Laravel AI SDK provides a unified and expressive API for working with AI models across multiple providers, while staying true to Laravel’s clean, developer-friendly philosophy.
What Is the Laravel AI SDK?
The Laravel AI SDK is an official package that allows you to interact with AI providers like OpenAI, Anthropic, and Gemini using a single, consistent API.
With it, you can:
Build intelligent AI agents
Generate text, images, and audio
Transcribe speech to text
Create and query vector embeddings
Implement semantic search and RAG (Retrieval-Augmented Generation)
Queue, stream, test, and scale AI workloads effortlessly
All of this is done in a way that feels native to Laravel.
Installation & Setup
Getting started takes only a few minutes.
composer require laravel/aiPublish the configuration and migration files:
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"Run migrations:
php artisan migrateThis creates tables that automatically store agent conversations and messages, enabling persistent AI memory.
Configuration & Providers
You can configure AI providers using environment variables or the config/ai.php file:
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
GEMINI_API_KEY=
ELEVENLABS_API_KEY=
MISTRAL_API_KEY=
COHERE_API_KEY=Laravel AI SDK supports multiple providers per feature, and you can even configure automatic failover if one provider becomes unavailable.
You may also route AI requests through custom base URLs, making it easy to integrate proxies, gateways, or enterprise security layers.
Agents: The Heart of the AI SDK
Agents are the core building blocks of the Laravel AI SDK.
An Agent is a PHP class that defines:
Instructions (system prompt)
Conversation context
Available tools
Optional structured output
Think of agents as specialized AI assistants—sales coaches, document analyzers, chatbots, or internal helpers.
Create one instantly:
php artisan make:agent SalesCoachAgents can:
Remember conversations
Call tools
Return structured JSON
Be queued or streamed
Be fully testable
Prompting an Agent
Prompting feels natural and expressive:
$response = SalesCoach::make()
->prompt('Analyze this sales transcript');
echo (string) $response;You can override the provider, model, or timeout per request without touching global config.
Conversation Memory (Built-In)
Using the RemembersConversations trait, Laravel can automatically store and reload conversation history.
$response = (new SalesCoach)
->forUser($user)
->prompt('Hello!');This allows agents to maintain context across multiple interactions—perfect for chatbots and assistants.
Structured Output (JSON-Safe AI)
Need predictable responses? Laravel AI SDK supports schema-based structured output.
$response = (new SalesCoach)->prompt('Analyze this...');
return $response['score'];This is extremely useful for dashboards, automation, scoring systems, and analytics.
Tools & RAG (Retrieval-Augmented Generation)
Agents can use tools to extend their capabilities:
Database or API access
Similarity search using embeddings
Secure random generators
Web search and file analysis
Laravel also includes a Similarity Search tool, allowing agents to query your database using vector embeddings—perfect for knowledge bases and document search.
Streaming, Queues & Broadcasting
The SDK supports:
Streaming responses (SSE)
Queued AI jobs
Broadcasting AI events
Vercel AI SDK streaming protocol
This makes it easy to build real-time AI experiences without blocking your application.
Images, Audio & Transcription
Beyond text, Laravel AI SDK supports:
Image Generation
Image::of('A donut on a kitchen counter')->generate();Text-to-Speech
Audio::of('I love coding with Laravel')->generate();Speech-to-Text
Transcription::fromStorage('audio.mp3')->generate();All media generation can be stored, queued, tested, and cached.
Embeddings, Vector Search & Reranking
Laravel provides native PostgreSQL vector support using pgvector.
You can:
Generate embeddings
Store them in vector columns
Perform cosine similarity search
Rerank search results using AI
This enables advanced AI search features directly inside Laravel—no external services required.
Testing & Fakes (Production-Ready AI)
One of the most impressive features is full test support.
You can fake:
Agents
Images
Audio
Embeddings
Files
Vector stores
This makes AI features fully testable and CI-safe—a huge win for real-world applications.









