What is the AI SDK that comes with Laravel 13? How to use it?

One of the most important new features in Laravel 13 is built-in AI SDK support. Laravel developers can now develop AI features directly within the framework, without needing extra packages for integration with services like OpenAI, Gemini, and Anthropic.

In this article, you will learn what Laravel 13 AI SDK is, how to use it, what can be done with it, and how it works with a simple example.


🧠 What is Laravel AI SDK?

Laravel AI SDK is a layer that brings together different AI providers under a single API.

So think about this:

You previously wrote separate code for OpenAI and for Gemini.
👉 Now you manage them all with a single Laravel API.

Supported providers:

  • OpenAI
  • Google Gemini
  • Anthropic (Claude)
  • Mistral
  • Groq
  • Ollama (local AI)
  • Azure OpenAI

⚡ What can you do with the Laravel AI SDK?

With Laravel 13, you can easily develop the following AI scenarios:

🎯 Text Processing

  • Creating a blog post
  • Generating product descriptions
  • Text summarization
  • Language translation

🤖 Chatbot & Agent

  • Customer support bot
  • CV analysis system
  • AI consultant

🧾 Structured Output

  • Generating data in JSON format.
  • Automatic form filling

🔍 Embedding & Search

  • Semantic search (RAG system)
  • AI-powered filtering

🎙️ Audio & Visuals

  • Speech to text
  • Text to speech
  • Image generation

🏗️ Installation

First, install the package:

 
composer require laravel/ai
 

Next, config and migration:

 
php artisan vendor:publish --provider = "Laravel\Ai\AiServiceProvider"
php artisan migrate
 

Add the API key to your .env file:

 
OPENAI_API_KEY=your_key_here
 

⚙️ System Requirements

For Laravel 13 AI SDK:

  • PHP 8.3+
  • Laravel 13
  • Composer
  • API Key (OpenAI, etc.)

Additional important point:

👉 No GPU required (if you're using cloud AI)
👉 If you use the local model (Ollama) → RAM/CPU will be required.


🧩 Basic Logic: Agent Structure

Laravel AI SDK goes a step further than the classic "send prompt" logic.

Main structure:

  • Agent → AI character
  • Instruction → tells you what to do.
  • Prompt → user request
  • Memory → speech history

🧪 Simple Example: Creating a Product Description

1. Create an Agent

 
namespace App\Ai\Agents;

use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Promptable;

class ProductDescriptionAgent implements Agent
{
use Promptable;

public function instructions(): string
{
return 'You are a professional e-commerce copywriter. Write short product descriptions in Turkish.';
}
}
 

2. Usage

 
use App\Ai\Agents\ProductDescriptionAgent;

Route::get('/ai-demo', function () {
$response = ProductDescriptionAgent::make()->prompt(
'Write a short description for a black leather men's wallet'
);

return (string) $response;
});
 

🎉 It's out!

 
This stylish and durable black leather men's wallet is ideal for everyday use with its modern design and convenient compartments.
 

📦 Structured Output (JSON Output)

You can get not only text but also structured data from AI:

For example:

 
{
"title": "Product name"
"description": "Description"
Rating: 4.5
}
 

This feature is especially important for:

  • Admin panel
  • Automation systems
  • API outputs

It is very powerful.


🔥 Streaming (Live Typing)

With the Laravel AI SDK, you can create typing display features similar to ChatGPT:

 
->stream()
 

In this way:

  • Chat application
  • Live support
  • AI editor

Systems like these can be created.


🧠 Embedding & AI Search

One of the most powerful features that comes with Laravel 13:

👉 Semantic search (AI search)

Example:

  • User: "cheap shoes"
  • System: finds the products that are closest in meaning.

This structure:

  • Blog search
  • Product filtering
  • SaaS platforms

It is very critical.


⚖️ Advantages

The biggest advantages of Laravel AI SDK:

✔ Multiple AI support with a single API
✔ Clean and sustainable code structure
✔ Agent architecture
✔ Structured output
✔ Streaming support
✔ RAG / embedding infrastructure


⚠️ Important Considerations

  • AI services are paid (token-based).
  • Rate limit management should be implemented.
  • Using caching and queries is recommended.
  • Sensitive data should be sent with care.

🎯 Real-Life Use Cases

Here are a few examples specific to your projects:

  • Blog post generator in the admin panel.
  • CV builder (adding AI to KitResume)
  • Automatic classification of customer messages
  • Product description generation (e-commerce)
  • AI-powered search system

⚔️ Laravel 13 AI SDK vs. Old AI Integration Method

Feature Laravel 13 AI SDK Old Method (Laravel 10-12 + Packages)
Setup Single package ( laravel/ai ) Separate packages for each service.
API Structure Unified (single API) Disorganized, dependent on the provider.
Changing Provider Very easy (with config) You need to change the code.
Agent Structure Native support Written manually.
Prompt Management Central (Agent class) Distributed within the controller
Structured Output Built-in Manual parsing
Streaming Native ( ->stream() ) Additional package required.
Conversation Memory Ready-made (DB-based) You need to write it yourself.
Tool Calling Built-in Complicated
Embedding Native support External service + manual
Vector Search Integrated Additional infrastructure is required.
Local AI (Ollama) Supported Additional integration is required.
Code Cleanup Very high Middle
Maintainability High Low / Medium
Learning Curve Easier More difficult
Development Rate Very fast 🚀 Slow

📌 Result

With Laravel 13, AI integration is now available:

👉 no extra package required
👉 native
👉 scalable

It transformed into a structure.

This makes Laravel more than just a backend framework,
It is transforming into an AI-powered application development platform .

Keywords: Laravel 13 AI, what is Laravel AI SDK, Laravel OpenAI integration, Laravel AI agent usage

Frequently Asked Questions

What is Laravel AI SDK?

Laravel AI SDK is a built-in integration layer that allows developers to interact with multiple AI providers using a single API.

Does Laravel AI require GPU?

No, if you use cloud-based AI providers like OpenAI, no GPU is required.

Can Laravel AI work with local models?

Yes, Laravel supports local AI models via tools like Ollama. bunların bir de Türkçelerini verir misin?

Comments

Log in or sign up to write a comment
Giriş
Sign Up