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

ActiveLibrary[API Development](/categories/api)

openai-php/laravel
==================

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

v0.19.1(2mo ago)3.7k7.6M—0.1%263[5 issues](https://github.com/openai-php/laravel/issues)[8 PRs](https://github.com/openai-php/laravel/pulls)20MITPHPPHP ^8.2.0CI passing

Since Dec 26Pushed today45 watchersCompare

[ Source](https://github.com/openai-php/laravel)[ Packagist](https://packagist.org/packages/openai-php/laravel)[ Fund](https://www.paypal.com/paypalme/enunomaduro)[ GitHub Sponsors](https://github.com/gehrisandro)[ RSS](/packages/openai-php-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (51)Used By (20)

 [![GitHub Workflow Status (master)](https://camo.githubusercontent.com/9b5cd89503ff72dcb851fc486957d3c4bd976569a67b9bb1ce306599c1cb6fdd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f70656e61692d7068702f6c61726176656c2f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d726f756e642d737175617265)](https://github.com/openai-php/laravel/actions) [![Total Downloads](https://camo.githubusercontent.com/6a1c4ae8216497114ded6bd858a32b6aefaf8325523573ca2fc4460f165bd4f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f70656e61692d7068702f6c61726176656c)](https://packagist.org/packages/openai-php/laravel) [![Latest Version](https://camo.githubusercontent.com/e2809c4e8588860cffc1dc375ae9a90d8a3eb725dee58afaeb42ffd11ff9bc7b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f70656e61692d7068702f6c61726176656c)](https://packagist.org/packages/openai-php/laravel) [![License](https://camo.githubusercontent.com/a23c4458f94b4da93c4cc295173f74f0fea13a50262954fb99f8d91658ccae82/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f70656e61692d7068702f6c61726176656c)](https://packagist.org/packages/openai-php/laravel)

---

**OpenAI PHP** for Laravel is a community-maintained PHP API client that allows you to interact with the [Open AI API](https://platform.openai.com/docs/api-reference/introduction). If you or your business relies on this package, it's important to support the developers who have contributed their time and effort to create and maintain this valuable tool:

- Nuno Maduro: **[github.com/sponsors/nunomaduro](https://github.com/sponsors/nunomaduro)**
- Sandro Gehri: **[github.com/sponsors/gehrisandro](https://github.com/sponsors/gehrisandro)**

> **Note:** This repository contains the integration code of the **OpenAI PHP** for Laravel. If you want to use the **OpenAI PHP** client in a framework-agnostic way, take a look at the [openai-php/client](https://github.com/openai-php/client) repository.

Get Started
-----------

[](#get-started)

> **Requires [PHP 8.2+](https://www.php.net/releases/)**

First, install OpenAI via the [Composer](https://getcomposer.org/) package manager:

```
composer require openai-php/laravel
```

Next, execute the install command:

```
php artisan openai:install
```

This will create a `config/openai.php` configuration file in your project, which you can modify to your needs using environment variables. Blank environment variables for the OpenAI API key and organization id are already appended to your `.env` file.

```
OPENAI_API_KEY=sk-...
OPENAI_ORGANIZATION=org-...
```

Finally, you may use the `OpenAI` facade to access the OpenAI API:

```
use OpenAI\Laravel\Facades\OpenAI;

$response = OpenAI::responses()->create([
    'model' => 'gpt-5',
    'input' => 'Hello!',
]);

echo $response->outputText; // Hello! How can I assist you today?

```

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

[](#configuration)

Configuration is done via environment variables or directly in the configuration file (`config/openai.php`).

### OpenAI API Key and Organization

[](#openai-api-key-and-organization)

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 .

```
OPENAI_API_KEY=
OPENAI_ORGANIZATION=
```

### OpenAI Project

[](#openai-project)

For implementations that require a project ID, you can specify the OpenAI project ID in your environment variables.

```
OPENAI_PROJECT=proj_...
```

### OpenAI API Base URL

[](#openai-api-base-url)

The base URL for the OpenAI API. By default, this is set to `api.openai.com/v1`.

```
OPENAI_BASE_URL=
```

### Request Timeout

[](#request-timeout)

The timeout may be used to specify the maximum number of seconds to wait for a response. By default, the client will time out after 30 seconds.

```
OPENAI_REQUEST_TIMEOUT=
```

Usage
-----

[](#usage)

For usage examples, take a look at the [openai-php/client](https://github.com/openai-php/client) repository.

Testing
-------

[](#testing)

The `OpenAI` facade comes with a `fake()` method that allows you to fake the API responses.

The fake responses are returned in the order they are provided to the `fake()` method.

All responses are having a `fake()` method that allows you to easily create a response object by only providing the parameters relevant for your test case.

```
use OpenAI\Laravel\Facades\OpenAI;
use OpenAI\Responses\Responses\CreateResponse;

OpenAI::fake([
    CreateResponse::fake([
        'choices' => [
            [
                'text' => 'awesome!',
            ],
        ],
    ]),
]);

$response = OpenAI::responses()->create([
    'model' => 'gpt-5',
    'input' => 'PHP is ',
]);

expect($response->outputText)->toBe('awesome!');
```

After the requests have been sent there are various methods to ensure that the expected requests were sent:

```
use OpenAI\Resources\Responses;

// assert completion create request was sent
OpenAI::assertSent(Responses::class, function (string $method, array $parameters): bool {
    return $method === 'create' &&
        $parameters['model'] === 'gpt-5' &&
        $parameters['prompt'] === 'PHP is ';
});
```

For more testing examples, take a look at the [openai-php/client](https://github.com/openai-php/client#testing) repository.

---

OpenAI PHP for Laravel is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.

###  Health Score

72

—

ExcellentBetter than 100% of packages

Maintenance94

Actively maintained with recent releases

Popularity75

Solid adoption and visibility

Community48

Growing community involvement

Maturity61

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~30 days

Recently: every ~41 days

Total

40

Last Release

62d ago

PHP version history (2 changes)v0.2.0PHP ^8.1.0

v0.12.0PHP ^8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/86cfef5c1f5195df1a9db17a5f8ecb34455e1f0133a725de9acf7f2fb26ac6a1?d=identicon)[nunomaduro](/maintainers/nunomaduro)

---

Top Contributors

[![nunomaduro](https://avatars.githubusercontent.com/u/5457236?v=4)](https://github.com/nunomaduro "nunomaduro (63 commits)")[![gehrisandro](https://avatars.githubusercontent.com/u/25097194?v=4)](https://github.com/gehrisandro "gehrisandro (37 commits)")[![iBotPeaches](https://avatars.githubusercontent.com/u/611784?v=4)](https://github.com/iBotPeaches "iBotPeaches (30 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![cosmastech](https://avatars.githubusercontent.com/u/42181698?v=4)](https://github.com/cosmastech "cosmastech (3 commits)")[![peterramsing](https://avatars.githubusercontent.com/u/3523268?v=4)](https://github.com/peterramsing "peterramsing (2 commits)")[![pb30](https://avatars.githubusercontent.com/u/259602?v=4)](https://github.com/pb30 "pb30 (2 commits)")[![xenon87](https://avatars.githubusercontent.com/u/116573?v=4)](https://github.com/xenon87 "xenon87 (2 commits)")[![marlonbasten](https://avatars.githubusercontent.com/u/31259698?v=4)](https://github.com/marlonbasten "marlonbasten (1 commits)")[![megoxv](https://avatars.githubusercontent.com/u/87904671?v=4)](https://github.com/megoxv "megoxv (1 commits)")[![peterfox](https://avatars.githubusercontent.com/u/1716506?v=4)](https://github.com/peterfox "peterfox (1 commits)")[![saeedhosan](https://avatars.githubusercontent.com/u/78552486?v=4)](https://github.com/saeedhosan "saeedhosan (1 commits)")[![sweptsquash](https://avatars.githubusercontent.com/u/9886472?v=4)](https://github.com/sweptsquash "sweptsquash (1 commits)")[![trippo](https://avatars.githubusercontent.com/u/497169?v=4)](https://github.com/trippo "trippo (1 commits)")[![krishnahimself](https://avatars.githubusercontent.com/u/19906424?v=4)](https://github.com/krishnahimself "krishnahimself (1 commits)")[![BadJacky](https://avatars.githubusercontent.com/u/113529280?v=4)](https://github.com/BadJacky "BadJacky (1 commits)")[![butschster](https://avatars.githubusercontent.com/u/773481?v=4)](https://github.com/butschster "butschster (1 commits)")[![edvardsr](https://avatars.githubusercontent.com/u/60649302?v=4)](https://github.com/edvardsr "edvardsr (1 commits)")[![fredmarmillod](https://avatars.githubusercontent.com/u/9134609?v=4)](https://github.com/fredmarmillod "fredmarmillod (1 commits)")[![HijenHEK](https://avatars.githubusercontent.com/u/22668814?v=4)](https://github.com/HijenHEK "HijenHEK (1 commits)")

---

Tags

clientlaravelopen-aiphpapiclientlaravelsdklanguageprocessingnaturalcodexGPT-3openaidall-e

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k22.6M232](/packages/openai-php-client)[openai-php/symfony

Symfony Bundle for OpenAI

215715.5k3](/packages/openai-php-symfony)

PHPackages © 2026

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