Development

Laravel AI SDK in Laravel 12.x: Practical Guide

Editor | March 3, 2026 | 5 min read

Laravel 12.x includes an official AI SDK that gives you a consistent way to build AI features inside a normal Laravel app. Instead of wiring each provider manually, you work through Laravel-first abstractions for agents, conversations, tools, and structured output.

Official docs: Laravel AI SDK

Quick Start

Install and publish the package, then run migrations so conversation storage is ready:

composer require laravel/ai
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
php artisan migrate

The docs show conversation tables used by the SDK, so your prompts and replies can be tracked in application context.

Core Idea: Agents

The main building block is an Agent class. You generate one with:

php artisan make:agent SalesCoach

For structured responses, the docs also show:

php artisan make:agent SalesCoach --structured

Each agent can hold:

  • instructions (system behavior)
  • conversation context
  • callable tools
  • structured output schema

This keeps AI logic organized like any other Laravel domain code.

Features You Can Build

From the 12.x docs, the SDK covers a broad set of capabilities:

  • text generation and multi-turn conversation
  • streaming responses (plus broadcasting/queueing options)
  • tool calling and provider tools
  • images, audio, and transcription workflows
  • embeddings and reranking
  • files and vector store workflows
  • failover patterns and testing support

That makes it possible to build chat, assistants, semantic search, and document workflows without mixing multiple SDK styles.

Provider Flexibility

The docs list support across multiple labs/providers (for example OpenAI, Anthropic, Gemini, and others depending on feature type). The key advantage is that your app code can stay mostly stable while you switch models or providers per use case.

In practice, this means:

  • use one provider for chat quality
  • another for embeddings cost/performance
  • keep failover paths for reliability
Testing Matters

The SDK docs include dedicated testing sections across agents, media, embeddings, reranking, files, and vector stores. This is important because AI features need deterministic tests around:

  • prompt-to-schema compliance
  • tool invocation behavior
  • error and fallback handling
  • response shaping before UI delivery
Final Take

Laravel AI SDK is a strong option if you want AI features to feel native to Laravel architecture instead of bolted-on API calls. Start with one agent, add structured output early, and build tests before expanding to more advanced flows like embeddings or vector stores.