PHPackages                             matrixbrains/laravel-ai - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. matrixbrains/laravel-ai

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

matrixbrains/laravel-ai
=======================

Laravel AI wrapper package with multiple AI provider drivers (OpenAI, Gemini, Claude, Mistral)

1.0.0(8mo ago)186↓50%1MITPHPPHP ^8.2

Since Sep 9Pushed 7mo agoCompare

[ Source](https://github.com/matrixbrains/laravel-ai)[ Packagist](https://packagist.org/packages/matrixbrains/laravel-ai)[ Docs](https://github.com/matrixbrains/laravel-ai)[ RSS](/packages/matrixbrains-laravel-ai/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (1)

Laravel AI Wrapper
==================

[](#laravel-ai-wrapper)

[![License](https://camo.githubusercontent.com/b8cadaa967891081f8f165695470689986c028821dd8a040132f6e661795dc0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c7565)](LICENSE)[![PHP](https://camo.githubusercontent.com/d86b1922e8fc785afad2a5d6b83ad6c8c41ce23d23bdac02fb8b449eaa62b2c2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312532422d383839324246)](https://www.php.net/)[![Laravel](https://camo.githubusercontent.com/9eec6568d060e12c2dc9c5a285a9b3da7a53da9e5632ba5d311b662aa9db6dd0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31302532422d454633423244)](https://laravel.com/)

A **simple, elegant Laravel package** to integrate multiple AI providers with a unified interface. Supports **OpenAI, Google Gemini, Anthropic Claude, and Mistral AI**.

---

Features
--------

[](#features)

- Unified `Ai::ask()` method for all providers
- Supports **text generation** &amp; **chat prompts**
- Easily switch between AI providers via `.env`
- Extensible: add your own AI driver if needed
- Free tier support: Google Gemini &amp; Mistral
- Fully ready for Laravel applications

---

Installation
------------

[](#installation)

Require the package via Composer:

```
composer require matrixbrains/laravel-ai
```

Publish the config file:

```
php artisan vendor:publish --provider="Matrixbrains\LaravelAi\AiServiceProvider" --tag="config"
```

---

Configuration
-------------

[](#configuration)

Edit your `.env`:

```
AI_DRIVER=gemini   # Options: openai, gemini, claude, mistral

# OpenAI
OPENAI_API_KEY=your_openai_key
OPENAI_MODEL=gpt-4o-mini

# Google Gemini
GEMINI_API_KEY=your_gemini_key
GEMINI_MODEL=gemini-2.0-flash

# Anthropic Claude
CLAUDE_API_KEY=your_claude_key
CLAUDE_MODEL=claude-3-5-sonnet-20240620

# Mistral
MISTRAL_API_KEY=your_mistral_key
MISTRAL_MODEL=mistral-small
```

---

Usage
-----

[](#usage)

Use the facade to send a prompt:

```
use Matrixbrains\LaravelAi\Facades\Ai;

$response = Ai::ask("Write a short poem about Laravel.");
echo $response;
```

> The same method works for all drivers. Just switch `AI_DRIVER` in `.env` to change the provider.

---

### Example with multiple drivers

[](#example-with-multiple-drivers)

```
// OpenAI
config(['ai.default' => 'openai']);
$response = Ai::ask("Explain AI in simple terms.");

// Google Gemini
config(['ai.default' => 'gemini']);
$response = Ai::ask("Generate a motivational quote.");

// Claude
config(['ai.default' => 'claude']);
$response = Ai::ask("Write a haiku about coding.");

// Mistral
config(['ai.default' => 'mistral']);
$response = Ai::ask("Summarize the latest Laravel release notes.");
```

---

Extending with custom drivers
-----------------------------

[](#extending-with-custom-drivers)

Add a new driver in `src/Drivers` and register it in `AiManager.php`. All drivers should implement the `AiDriver` interface:

```
class CustomAiDriver
{
    public function ask(string $prompt): string
    {
        // Your AI API integration
    }
}
```

---

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/my-feature`)
3. Commit your changes (`git commit -m 'Add new feature'`)
4. Push to the branch (`git push origin feature/my-feature`)
5. Open a Pull Request

---

License
-------

[](#license)

This package is open-source and licensed under the [MIT License](LICENSE.md).

---

Supported AI Providers
----------------------

[](#supported-ai-providers)

ProviderFree TierNotesOpenAILimitedRequires API keyGoogle GeminiYes1,500 requests/day freeAnthropic ClaudeLimitedFree credits for new usersMistral AIYesSmall models free tier---

✨ **Matrixbrains Laravel AI** makes integrating multiple AI tools seamless for your Laravel apps.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance61

Regular maintenance activity

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

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

245d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/23115789373de81f8331bff5811a2b6def118b847828564f7e7c76426c8cda22?d=identicon)[Vikram Mevasiya](/maintainers/Vikram%20Mevasiya)

---

Top Contributors

[![vikrammevasiya](https://avatars.githubusercontent.com/u/27346101?v=4)](https://github.com/vikrammevasiya "vikrammevasiya (2 commits)")

---

Tags

laravelaiopenaiGeminiclaudemistral

### Embed Badge

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

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

###  Alternatives

[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[symfony/ai-platform

PHP library for interacting with AI platform provider.

51927.7k136](/packages/symfony-ai-platform)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[vizra/vizra-adk

Vizra Agent Development Kit - A comprehensive Laravel package for building intelligent AI agents.

29026.1k](/packages/vizra-vizra-adk)

PHPackages © 2026

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