PHPackages                             capevace/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. capevace/laravel-gpt

ActiveLibrary[API Development](/categories/api)

capevace/laravel-gpt
====================

A Laravel package for interacting with OpenAI's GPT-3.

v1.0.1(3y ago)131312[3 PRs](https://github.com/Capevace/laravel-gpt/pulls)MITPHPPHP ^8.1

Since Dec 13Pushed 2y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (14)Versions (6)Used By (0)

 [ ![](https://user-images.githubusercontent.com/10093858/207289815-1656ca5a-9473-4c32-a099-35f20ff0f60c.png) ](https://github.com/capevace/laravel-gpt)laravel-gpt
===========

[](#laravel-gpt)

 This package provides a **type-safe** interface for making requests to the [GPT-3 API](https://beta.openai.com/docs/api-reference/introduction).

 [ ![Latest Version on Packagist](https://camo.githubusercontent.com/fe3dbc4742f5f1cc0ef93e96badf55020109e034655d8fc8ea1b11314dc6f4c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63617065766163652f6c61726176656c2d6770742e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/capevace/laravel-gpt) [ ![GitHub Tests Action Status](https://camo.githubusercontent.com/9f77388fc7c23203bbabb378c296320b261ea2f7404a51920b49b9066897dd1d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f63617065766163652f6c61726176656c2d6770742f72756e2d74657374733f6c6162656c3d7465737473) ](https://github.com/capevace/laravel-gpt/actions?query=workflow%3Arun-tests+branch%3Amain) [ ![Total Downloads](https://camo.githubusercontent.com/f2f076d1455552f4fa218fb5a18fefcdf5c97388db650c6c280d63458179e3e4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63617065766163652f6c61726176656c2d6770742e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/capevace/laravel-gpt)

```
use Capevace\GPT\Facades\GPT;

$response = GPT::generate(
    'Name a thing that is blue.',
    model: 'text-davinci-003',
    maxTokens: 400,
    frequencyPenalty: 1.0,
);

echo $response->first(); // "The sky"
```

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

[](#installation)

You can install the package via composer:

```
composer require capevace/laravel-gpt
```

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

[](#configuration)

You will need an API key for the OpenAI GPT-3 API. Once you have obtained an API key, you can configure it in your .env file by adding the following line:

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

You could also publish the config file directly, **but this really probably isn't necessary**:

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

Usage
-----

[](#usage)

The `Capevace\GPT\GPTService` class provides methods for making requests to the GPT-3 API. You can inject it into controllers or use the Facade to access the container.

```
# Access via injection

use Capevace\GPT\GPTService;

class MyController extends Controller {
    protected GPTService $gpt;

    public function __construct(GPTService $gpt) {
        $this->gpt = $gpt;
    }

    public function index() {
        $this->gpt->generate(
            // ..
        );
    }

}

# Access via Facade

use Capevace\GPT\Facades\GPT;

GPT::generate(/* .. */);
```

### GPT::generate(*&lt;prompt&gt;*, *\[...options\]*)

[](#gptgenerateprompt-options)

The `generate` method returns a `GPTResponse` object that contains the response from the GPT-3 API. If no text is returned (empty string), the method will throw an error.

`generate` takes the following arguments:

- `prompt` (required): the prompt to send to the GPT-3 API
- `model`: the GPT-3 model to use (defaults to text-davinci-003)
- `temperature`: a value between 0 and 1 that determines how "creative" the response will be (defaults to 0.83)
- `maxTokens`: the maximum number of tokens (i.e., words) to return in the response (defaults to 1200)
- `stop`: a string that, when encountered in the response, will cause the response to end (defaults to null)
- `frequencyPenalty`: a value between 0 and 1 that determines how much the model will penalize frequent words (defaults to 0.11)
- `presencePenalty`: a value between 0 and 1 that determines how much the model will penalize words that don't appear in the prompt (defaults to 0.03)

#### Example

[](#example)

```
use Capevace\GPT\Facades\GPT;

$response = GPT::generate(
    'Generate a list of things that are blue.',
    model: 'text-davinci-003',
    maxTokens: 400,
    frequencyPenalty: 1.0,
);
```

### Handling responses

[](#handling-responses)

The `generate` method returns a `GPTResponse` object that contains the response from the GPT-3 API.

It has two methods:

- `$response->first()` (*string*): returns the first text suggested by GPT-3
- `$response->all()` (*array*): returns a list of all the text choices suggested by GPT-3

#### Example

[](#example-1)

```
use Capevace\GPT\Facades\GPT;

$response = GPT::generate(
    'Name a thing that is blue.',
    model: 'text-davinci-003',
    maxTokens: 400,
    frequencyPenalty: 1.0,
);

$firstChoice = $response->first(); // "the sky"

$allChoices = $response->all(); // ["the sky", "the ocean" ...]
```

### Error handling

[](#error-handling)

If an error occurs while making a request to the GPT-3 API, the `generate()` method will throw a `Capevace\GPT\Support\GPTException` exception.

`laravel-gpt` will also throw an error, if a response does not contain any text (empty string).

#### Example

[](#example-2)

```
use Capevace\GPT\Facades\GPT;
use Capevace\GPT\Support\GPTException;
use Exception;

try {
    $response = GPT::generate('Do nothing.');
} catch (GPTException $e) {
    // Exception will be thrown, as the response text is ""
} catch (Exception $e) {
    // Catch connectivity errors etc.
}
```

---

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 74.2% 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

1246d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e572442281b0c1b6e8e8f966cc908161a66c4c822e950ff278f8f90dc4f2d2cd?d=identicon)[mateffy](/maintainers/mateffy)

---

Top Contributors

[![Capevace](https://avatars.githubusercontent.com/u/10093858?v=4)](https://github.com/Capevace "Capevace (23 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (4 commits)")

---

Tags

aigptgpt-3laravellaravel-packageopenaiphpphp-librarylaravelaiGPT-3openaillmgpttext-generationLanguage Modelcapevace

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

47073.9k5](/packages/deepseek-php-deepseek-php-client)[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)[vectorifyai/vectorify-laravel

Vectorify package for Laravel. The fastest way to ask AI about your data.

206.1k](/packages/vectorifyai-vectorify-laravel)

PHPackages © 2026

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