PHPackages                             mastashake08/laravel-openai-api - 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. mastashake08/laravel-openai-api

ActiveLibrary[API Development](/categories/api)

mastashake08/laravel-openai-api
===============================

Add an OpenAI API and Artisan command easily into your projects. Generate images, or text. Can be integrated with Laravel Sanctum for token based access.

1.8.4(3y ago)92302[1 PRs](https://github.com/mastashake08/laravel-openai-api/pulls)MITPHPPHP ^8.1

Since Feb 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mastashake08/laravel-openai-api)[ Packagist](https://packagist.org/packages/mastashake08/laravel-openai-api)[ Docs](https://github.com/mastashake08/laravel-openai-api)[ Fund](https://cash.me/$mastashake08)[ GitHub Sponsors](https://github.com/mastashake08)[ RSS](/packages/mastashake08-laravel-openai-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (55)Used By (0)

Add an OpenAI API and Artisan commands easily into your projects.
=================================================================

[](#add-an-openai-api-and-artisan-commands-easily-into-your-projects)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5681a0d3d28d8337d3322635bbc90b2f5ecc193135433e5339b50555b3c52fd2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617374617368616b6530382f6c61726176656c2d6f70656e61692d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mastashake08/laravel-openai-api)[![GitHub Tests Action Status](https://camo.githubusercontent.com/bd2747c4ef4004b6818a19251f3ed2fdcdc67fe92690f0a568888a40c8505435/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d617374617368616b6530382f6c61726176656c2d6f70656e61692d6170692f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/mastashake08/laravel-openai-api/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/c0fd8c09eb43790a0abf94e539d40fc785ef4b6f26504f31363845b0234f39d4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d617374617368616b6530382f6c61726176656c2d6f70656e61692d6170692f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/mastashake08/laravel-openai-api/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/855a31cc0fcda46f977511a0c5aaf6870282856315fdba944f2eaf6c929124e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617374617368616b6530382f6c61726176656c2d6f70656e61692d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mastashake08/laravel-openai-api)

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

[](#installation)

You can install the package via composer:

```
composer require mastashake08/laravel-openai-api
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="openai-api-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="openai-api-config"
```

This is the contents of the published config file:

```

    /*
    |--------------------------------------------------------------------------
    | OpenAI API Key and Organization
    |--------------------------------------------------------------------------
    |
    | Here you may specify your OpenAI API Key and organization. This will be
    | used to authenticate with the OpenAI API - you can find your API key
    | and organization on your OpenAI dashboard, at https://openai.com.
    */

    'api_key' => env('OPENAI_API_KEY'),
    'organization' => env('OPENAI_ORGANIZATION'),
    'api_url' = env('OPENAI_API_URL')

];

```

Usage
-----

[](#usage)

### Via Code

[](#via-code)

```
$laravelOpenaiApi = new Mastashake\LaravelOpenaiApi();
echo $laravelOpenaiApi->generateResult($type, $data);
```

### Via Artisan

[](#via-artisan)

```
php artisan laravel-openai-api:generate-result
```

### Via API

[](#via-api)

You set the OPENAI\_API\_URL in the .env file if a value is not set then it defaults to /api/generate-result

```
/api/generate-result POST {openai_data}

```

The data object requires a `type` property that is either set to text or image. Depending on which type then provide the JSON referenced in the [OpenAI API Reference](https://platform.openai.com/docs/api-reference/images/create)

#### Text Example

[](#text-example)

```
{
  "type": "text",
  "prompt": "Rust is",
  "n": 1,
  "model": "text-davinci-003",
  "max_tokens": 16
}

```

#### Image Example

[](#image-example)

```
{
  "type": "image",
  "prompt": "A cute baby sea otter",
  "n": 1,
  "size": "1024x1024"
}

```

Testing
-------

[](#testing)

```
composer test
```

Consider Sponsoring
-------------------

[](#consider-sponsoring)

Help me maintain this project, please consider looking at the [FUNDING](./.github/FUNDING.yml) file for more info.

Changelog
---------

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Jyrone Parker](https://github.com/mastashake08)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information. { "name": "mastashake08/laravel-openai-api", "description": "Add an OpenAI API easily into your projects.", "version": "1.6.0", "description": "Add an OpenAI API and Artisan command easily into your projects. Generate images, or text. Can be integrated with Laravel Sanctum for token based access.", "version": "1.6.2", "keywords": \[ "mastashake08", "laravel", "laravel-openai-api", "chatGPT", "OpenAI" "OpenAI", "Laravel Sanctum" \], "homepage": "", "license": "MIT", "minimum-stability": "dev", "prefer-stable": true }

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 94.8% 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 ~1 days

Total

52

Last Release

1129d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/878c27e5c8016259b8fd1524ad2f04a7b1795516a7cdea5f087fdfcc1dfd0124?d=identicon)[mastashake08](/maintainers/mastashake08)

---

Top Contributors

[![mastashake08](https://avatars.githubusercontent.com/u/1226096?v=4)](https://github.com/mastashake08 "mastashake08 (109 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

chatgptchatgpt-apilaravel-chatgptlaravel-openaiopenaiopenai-apilaravelopenaiChatGptlaravel-sanctummastashake08laravel-openai-api

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/mastashake08-laravel-openai-api/health.svg)

```
[![Health](https://phpackages.com/badges/mastashake08-laravel-openai-api/health.svg)](https://phpackages.com/packages/mastashake08-laravel-openai-api)
```

###  Alternatives

[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[ryangjchandler/bearer

Minimalistic token-based authentication for Laravel API endpoints.

8129.8k](/packages/ryangjchandler-bearer)[combindma/laravel-facebook-pixel

Meta pixel integration for Laravel

4956.9k](/packages/combindma-laravel-facebook-pixel)[stechstudio/laravel-hubspot

A Laravel SDK for the HubSpot CRM Api

2971.0k](/packages/stechstudio-laravel-hubspot)[creativecrafts/laravel-ai-assistant

A handy package to access and interact with OpenAi endpoint

141.1k](/packages/creativecrafts-laravel-ai-assistant)[njoguamos/laravel-plausible

A laravel package for interacting with plausible analytics api.

208.8k](/packages/njoguamos-laravel-plausible)

PHPackages © 2026

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