PHPackages                             katema/laravel-genai - 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. katema/laravel-genai

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

katema/laravel-genai
====================

Drop-in Generative AI for Laravel applications - opinionated, extensible, and production-ready

v1.0.1(4mo ago)02MITPHPPHP ^8.1|^8.2|^8.3

Since Dec 27Pushed 4mo agoCompare

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

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

Laravel GenAI
=============

[](#laravel-genai)

> Drop-in Generative AI for Laravel applications - opinionated, extensible, and production-ready.

[![Latest Version](https://camo.githubusercontent.com/df8c36645af5930ab41a2b76591eaeceba3a854e29627de7737b5c7ae89e1386/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6174656d612f6c61726176656c2d67656e61692e737667)](https://packagist.org/packages/katema/laravel-genai)[![License](https://camo.githubusercontent.com/c831271b63f7cd54f4dc85e2ed8704b4d936db112cc9a1d5c2c9a699e6d5bf93/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b6174656d612f6c61726176656c2d67656e61692e737667)](LICENSE.md)

Features
--------

[](#features)

- 🎯 **Simple API** - Clean, Laravel-native syntax
- 🔌 **Provider Agnostic** - OpenAI, Claude, Gemini, Ollama, or custom
- 📝 **Prompt Management** - Version control your prompts
- 💾 **Context Management** - Maintain conversation context
- 🎨 **Model Integration** - Add AI to Eloquent models with traits
- 📊 **Cost Tracking** - Monitor tokens and costs
- 🔒 **Production Ready** - Rate limiting, validation, error handling
- 🚀 **Queue Support** - Async AI operations

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

[](#installation)

```
composer require katema/laravel-genai
php artisan genai:install
```

Set your API key in `.env`:

```
GENAI_PROVIDER=openai
OPENAI_API_KEY=your-api-key-here
OPENAI_MODEL=gpt-4-turbo-preview
```

Quick Start
-----------

[](#quick-start)

### Basic Text Generation

[](#basic-text-generation)

```
use Katema\LaravelGenAI\Facades\AI;

$response = AI::text('Write a product description for a coffee mug');
echo $response->content;
```

### Chat Conversations

[](#chat-conversations)

```
$messages = [
    ['role' => 'user', 'content' => 'What is Laravel?'],
];

$response = AI::chat($messages);
echo $response->content;
```

### Structured JSON Output

[](#structured-json-output)

```
$data = AI::json('Generate a user profile with name, email, and bio');
// Returns: ['name' => 'John Doe', 'email' => 'john@example.com', 'bio' => '...']
```

### With Context

[](#with-context)

```
$response = AI::withContext([
    'user' => auth()->user()->name,
    'company' => 'Acme Corp'
])->text('Write a welcome email');
```

Prompt Management
-----------------

[](#prompt-management)

Create reusable prompts in `resources/prompts/`:

**prompts/marketing/product\_description.md:**

```
Generate a compelling product description for:

**Product:** {{product_name}}
**Category:** {{category}}
**Features:** {{features}}

Make it persuasive and highlight benefits.
```

Use it in your code:

```
$response = AI::prompt('marketing.product_description', [
    'product_name' => 'Smart Coffee Maker',
    'category' => 'Kitchen Appliances',
    'features' => 'WiFi enabled, programmable, auto-shutoff'
]);
```

Model Integration
-----------------

[](#model-integration)

Add AI capabilities to your Eloquent models:

```
use Katema\LaravelGenAI\Traits\HasAI;

class Product extends Model
{
    use HasAI;
}
```

Then use it:

```
$product = Product::find(1);

// Generate a summary
$summary = $product->summarize();

// Generate a description
$description = $product->describe();

// Ask questions about the model
$insights = $product->insights('What makes this product unique?');
```

Multiple Providers
------------------

[](#multiple-providers)

Switch between providers easily:

```
// Use OpenAI
$response = AI::driver('openai')->text('Hello');

// Use Claude
$response = AI::driver('claude')->text('Hello');
```

Configure providers in `config/genai.php`:

```
'providers' => [
    'openai' => [
        'api_key' => env('OPENAI_API_KEY'),
        'model' => env('OPENAI_MODEL', 'gpt-4-turbo-preview'),
    ],
    'claude' => [
        'api_key' => env('CLAUDE_API_KEY'),
        'model' => env('CLAUDE_MODEL', 'claude-3-5-sonnet-20241022'),
    ],
],
```

Advanced Usage
--------------

[](#advanced-usage)

### System Prompts

[](#system-prompts)

```
$response = AI::withSystemPrompt('You are a helpful marketing assistant')
    ->chat($messages);
```

### Custom Options

[](#custom-options)

```
$response = AI::text('Write a story', [
    'temperature' => 0.9,
    'max_tokens' => 500,
    'model' => 'gpt-4'
]);
```

### Fresh Context

[](#fresh-context)

```
AI::withContext(['user' => 'Alice'])
    ->text('First request');

// Clear context for next request
AI::fresh()->text('Second request');
```

Cost Tracking
-------------

[](#cost-tracking)

All responses include cost and token information:

```
$response = AI::text('Hello');

echo $response->tokensUsed; // 150
echo $response->cost;       // 0.0045
echo $response->model;      // gpt-4-turbo-preview
echo $response->provider;   // openai
```

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

[](#configuration)

Publish the config file:

```
php artisan vendor:publish --tag=genai-config
```

Key configuration options:

```
// Default provider
'default' => env('GENAI_PROVIDER', 'openai'),

// Rate limiting
'rate_limits' => [
    'enabled' => true,
    'max_requests_per_minute' => 60,
    'max_tokens_per_day' => 100000,
],

// Safety
'safety' => [
    'prompt_injection_detection' => true,
    'output_validation' => true,
    'max_prompt_length' => 10000,
],
```

Artisan Commands
----------------

[](#artisan-commands)

```
# Install the package
php artisan genai:install

# Create a new prompt template
php artisan genai:prompt marketing.email

# Test a prompt
php artisan genai:test marketing.email --var="product=Coffee"
```

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

[](#contributing)

We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security issues, please email  instead of using the issue tracker.

License
-------

[](#license)

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

Credits
-------

[](#credits)

- [Aaron Katema](https://github.com/Aeronk)
- [All Contributors](../../contributors)

---

Built with ❤️ for the Laravel community

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance75

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

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

Every ~0 days

Total

2

Last Release

136d ago

PHP version history (2 changes)1.0.0PHP ^8.1

v1.0.1PHP ^8.1|^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/992caca8822584db4d06639319dabf1c00a418afdf8a3be7d6d735f0fda07429?d=identicon)[aaronkatema](/maintainers/aaronkatema)

---

Top Contributors

[![Aeronk](https://avatars.githubusercontent.com/u/13133754?v=4)](https://github.com/Aeronk "Aeronk (15 commits)")

---

Tags

laravelaiopenaiGeminiclaudellmgenerative-ai

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/katema-laravel-genai/health.svg)

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

###  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)[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)[llm-agents/agents

LLM Agents PHP SDK - Autonomous Language Model Agents for PHP

16410.9k9](/packages/llm-agents-agents)

PHPackages © 2026

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