PHPackages                             allanbernier/laravel-gpt - 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. [API Development](/categories/api)
4. /
5. allanbernier/laravel-gpt

ActiveLibrary[API Development](/categories/api)

allanbernier/laravel-gpt
========================

A Laravel package for interacting with the ChatGPT API with built-in support for function calling (tools)

v1.0.1(4mo ago)131MITPHPPHP ^8.1

Since Dec 18Pushed 4mo agoCompare

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

READMEChangelogDependencies (5)Versions (3)Used By (0)

Laravel GPT
===========

[](#laravel-gpt)

A powerful Laravel package for interacting with the ChatGPT API. This package provides a fluent, intuitive interface for making requests to OpenAI's ChatGPT API, with built-in support for function calling (tools).

Features
--------

[](#features)

- 🚀 Simple and fluent API for ChatGPT requests
- 🛠️ Built-in support for JSON Schema tools (function calling)
- 📦 Easy tool creation with artisan command
- 🔧 Type-safe tool implementation with `IChatTool` interface
- ⚡ Chainable methods for elegant code
- 🎯 Automatic tool execution based on ChatGPT's choices
- 🔄 Automatic retry logic for failed requests
- 📊 Usage tracking and token monitoring

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 9.0 (supports Laravel 9, 10, 11, and 12)

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

[](#installation)

Install the package via Composer:

```
composer require allanbernier/laravel-gpt
```

Publish the configuration file:

```
php artisan vendor:publish --tag=laravel-gpt-config
```

Add your OpenAI API key to `.env`:

```
OPENAI_API_KEY=your-api-key-here
```

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

[](#quick-start)

### 1. Installation

[](#1-installation)

```
composer require allanbernier/laravel-gpt
php artisan vendor:publish --tag=laravel-gpt-config
```

Add your OpenAI API key to `.env`:

```
OPENAI_API_KEY=your-api-key-here
```

### 2. First Use

[](#2-first-use)

```
use AllanBernier\LaravelGpt\ChatGPT;

$response = ChatGPT::new()
    ->prompt('Hello, how can I help you?')
    ->send();

echo $response->content;
```

### 3. Create a Tool

[](#3-create-a-tool)

Create a tool using the artisan command:

```
php artisan make:chatTool FindUser
```

This creates `app/ChatTools/FindUser.php`. Implement it:

```
namespace App\ChatTools;

use AllanBernier\LaravelGpt\ChatTool;
use App\Models\User;

class FindUser extends ChatTool
{
    /**
     * The name of the function.
     * If not set, defaults to 'find_user' (class name in snake_case).
     */
    public ?string $name = null;

    /**
     * A description of what the function does.
     */
    public ?string $description = 'Finds a user by their name';

    /**
     * Whether to enable strict schema adherence.
     * Defaults to false if not set.
     */
    public ?bool $strict = null;

    public function parameters(): array
    {
        return [
            'type' => 'object',
            'properties' => [
                'name' => ['type' => 'string', 'description' => 'The name of the user to find'],
            ],
            'required' => ['name'],
        ];
    }

    public function invoke(array $args): mixed
    {
        return User::where('name', 'like', "%{$args['name']}%")->first();
    }
}
```

### 3. Use the Tool

[](#3-use-the-tool)

```
use AllanBernier\LaravelGpt\ChatGPT;
use App\ChatTools\FindUser;

$response = ChatGPT::new()
    ->tool(FindUser::class)
    ->prompt('Could you find the user with email john@example.com?')
    ->send();

$user = $response->tool->execute();
echo "Tool: {$response->tool->name}\n"; # find_user
echo "Arguments: " . json_encode($response->tool->args) . "\n"; # {"email": "john@example.com"}
```

License
-------

[](#license)

MIT License - see [LICENSE](LICENSE) file for details.

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance74

Regular maintenance activity

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

145d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fcd3b374c775fd70099fedd27d9c1d276c1386b2d2ab53f84f924a2305474f44?d=identicon)[Allan Bernier](/maintainers/Allan%20Bernier)

---

Top Contributors

[![AllanBernier](https://avatars.githubusercontent.com/u/72750847?v=4)](https://github.com/AllanBernier "AllanBernier (5 commits)")

---

Tags

laravelaiopenaitoolschatllmgptChatGptfunction-callingassistant

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/allanbernier-laravel-gpt/health.svg)

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

###  Alternatives

[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)[claude-php/claude-php-sdk-laravel

Laravel integration for the Claude PHP SDK - Anthropic Claude API

5010.8k](/packages/claude-php-claude-php-sdk-laravel)[neuron-core/neuron-laravel

Official Neuron AI Laravel SDK.

10710.0k](/packages/neuron-core-neuron-laravel)

PHPackages © 2026

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