PHPackages                             mahbub/laravel-ai-chatbot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. mahbub/laravel-ai-chatbot

ActiveLibrary

mahbub/laravel-ai-chatbot
=========================

A robust Laravel package for AI Chatbots with built-in session history.

v1.0.0(1mo ago)21↓75%MITPHPPHP ^8.2

Since Jul 17Pushed 1w agoCompare

[ Source](https://github.com/mahbubur508/laravel-ai-chatbot)[ Packagist](https://packagist.org/packages/mahbub/laravel-ai-chatbot)[ RSS](/packages/mahbub-laravel-ai-chatbot/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

🤖 Laravel AI Chatbot
====================

[](#-laravel-ai-chatbot)

[![Laravel](https://camo.githubusercontent.com/5a580364ff3bd338370177402c5c050ff81a1933927e1e475c920c90850b38a3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d4646324432303f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/5a580364ff3bd338370177402c5c050ff81a1933927e1e475c920c90850b38a3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d4646324432303f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)[![PHP](https://camo.githubusercontent.com/d282cc3193faee11ee32307d0c4c9d809e8fafa4b3a8c12c6afbf35d4f7ec617/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d3737374242343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/d282cc3193faee11ee32307d0c4c9d809e8fafa4b3a8c12c6afbf35d4f7ec617/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d3737374242343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870266c6f676f436f6c6f723d7768697465)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d950db6c86e50159fac932cbb9871d4e20bf157bca42afe50a9cf6203d2e6abc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61686275622f6c61726176656c2d61692d63686174626f742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mahbub/laravel-ai-chatbot)[![Total Downloads](https://camo.githubusercontent.com/8ca074de4a70921437d102664e08aa56b2971a7f593f39330713630719033119/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61686275622f6c61726176656c2d61692d63686174626f742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mahbub/laravel-ai-chatbot)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

**A robust, flexible, and ultra-fast Laravel package for integrating AI Chatbots — with built-in database session history.**

Fully compatible with **OpenAI (ChatGPT)**, **Groq (Llama 3, Gemma)**, **OpenRouter**, and any other OpenAI-compatible API.

**[Features](#-features) • [Installation](#-installation) • [Usage](#-usage) • [API Reference](#-api-reference) • [License](#-license)**

---

✨ Features
----------

[](#-features)

⚡ **Multi-Provider Support**Works with OpenAI, Groq, OpenRouter, and more — out of the box.💾 **Built-in Session History**Auto-saves every user query and AI response to the database.⚙️ **Configurable System Prompts**Easily set up different personalities for your chatbot.🛣️ **Pre-configured API Routes**Ready-made endpoints for instant integration with React, Vue, or mobile apps.---

📦 Installation
--------------

[](#-installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require mahbub/laravel-ai-chatbot
```

### 2. Publish the configuration file

[](#2-publish-the-configuration-file)

```
php artisan vendor:publish --tag="ai-chatbot-config"
```

### 3. Publish &amp; run the migrations

[](#3-publish--run-the-migrations)

This creates the chat sessions and messages tables:

```
php artisan vendor:publish --tag="ai-chatbot-migrations"
php artisan migrate
```

### 4. Set your environment variables

[](#4-set-your-environment-variables)

Add the credentials for your preferred provider to your `.env` file.

**Option A — Official OpenAI (ChatGPT)**

```
OPENAI_API_KEY=sk-proj-your-openai-api-key
```

**Option B — Groq (Free &amp; Extremely Fast)**

```
OPENAI_API_KEY=gsk_your-groq-api-key
AI_CHATBOT_API_URL=https://api.groq.com/openai/v1
AI_CHATBOT_MODEL=llama-3.3-70b-versatile
```

**Option C — OpenRouter (Multi-model Free Tier)**

```
OPENAI_API_KEY=sk-or-v1-your-openrouter-key
AI_CHATBOT_API_URL=https://openrouter.ai/api/v1
AI_CHATBOT_MODEL=google/gemma-2-9b-it:free
```

---

🚀 Usage
-------

[](#-usage)

### Using the Service (Backend Logic)

[](#using-the-service-backend-logic)

Resolve the `AiChatService` anywhere in your application — controllers, jobs, commands, etc. — to handle custom logic:

```
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Mahbub\LaravelAiChatbot\Services\AiChatService;
use Mahbub\LaravelAiChatbot\Models\ChatSession;

class ChatController extends Controller
{
    protected $chatService;

    public function __construct(AiChatService $chatService)
    {
        $this->chatService = $chatService;
    }

    public function __invoke(Request $request)
    {
        // 1. Get or create a chat session for the user
        $session = ChatSession::firstOrCreate([
            'session_id' => $request->get('session_id') ?? Str::uuid(),
        ]);

        // 2. Send the message and get the AI response (history saved automatically)
        $aiResponse = $this->chatService->sendMessage($session, $request->get('message'));

        return response()->json([
            'session_id' => $session->session_id,
            'response'   => $aiResponse,
        ]);
    }
}
```

---

🔌 API Reference
---------------

[](#-api-reference)

The package ships with a ready-to-use endpoint for instant frontend integration.

### Send a Message

[](#send-a-message)

```
POST /api/chatbot/send

```

**Request Body**

```
{
    "session_id": "optional-uuid-string",
    "message": "Hello, who are you?"
}
```

**Response**

```
{
    "success": true,
    "session_id": "generated-or-provided-uuid",
    "response": "Hello! I am your helpful AI assistant."
}
```

FieldTypeRequiredDescription`session_id``string` (UUID)❌Existing session to continue a conversation. Auto-generated if omitted.`message``string`✅The user's message to send to the AI.---

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

---

Made with ❤️ by [Md. Mahbubur Rahman](https://github.com/mahbubur508) for the Laravel community

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance95

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

46d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/277972474?v=4)[mahbubur508](/maintainers/mahbubur508)[@mahbubur508](https://github.com/mahbubur508)

---

Top Contributors

[![mahbubur508](https://avatars.githubusercontent.com/u/277972474?v=4)](https://github.com/mahbubur508 "mahbubur508 (1 commits)")

### Embed Badge

![Health badge](/badges/mahbub-laravel-ai-chatbot/health.svg)

```
[![Health](https://phpackages.com/badges/mahbub-laravel-ai-chatbot/health.svg)](https://phpackages.com/packages/mahbub-laravel-ai-chatbot)
```

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.2k14.2M151](/packages/dedoc-scramble)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k6.1M53](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

331634.0k37](/packages/codewithdennis-filament-select-tree)[filament/support

Core helper methods and foundation code for all Filament packages.

2437.3M325](/packages/filament-support)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

24795.1k](/packages/harris21-laravel-fuse)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

25263.1k](/packages/vormkracht10-laravel-mails)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
