PHPackages                             webninjjacoder/open-ai-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. webninjjacoder/open-ai-laravel

ActiveLibrary[API Development](/categories/api)

webninjjacoder/open-ai-laravel
==============================

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

00PHP

Since May 27Pushed 1y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

 [![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://beta.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.1+](https://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;

$result = OpenAI::chat()->create([
    'model' => 'gpt-3.5-turbo',
    'messages' => [
        ['role' => 'user', 'content' => 'Hello!'],
    ],
]);

echo $result->choices[0]->message->content; // 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=
```

### 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\Completions\CreateResponse;

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

$completion = OpenAI::completions()->create([
    'model' => 'gpt-3.5-turbo-instruct',
    'prompt' => 'PHP is ',
]);

expect($completion['choices'][0]['text'])->toBe('awesome!');
```

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

```
// assert completion create request was sent
OpenAI::assertSent(Completions::class, function (string $method, array $parameters): bool {
    return $method === 'create' &&
        $parameters['model'] === 'gpt-3.5-turbo-instruct' &&
        $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

14

—

LowBetter than 2% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

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

### Community

Maintainers

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

---

Top Contributors

[![nunomaduro](https://avatars.githubusercontent.com/u/5457236?v=4)](https://github.com/nunomaduro "nunomaduro (48 commits)")[![gehrisandro](https://avatars.githubusercontent.com/u/25097194?v=4)](https://github.com/gehrisandro "gehrisandro (25 commits)")[![webninjjacoder](https://avatars.githubusercontent.com/u/28878862?v=4)](https://github.com/webninjjacoder "webninjjacoder (4 commits)")[![cosmastech](https://avatars.githubusercontent.com/u/42181698?v=4)](https://github.com/cosmastech "cosmastech (3 commits)")[![xenon87](https://avatars.githubusercontent.com/u/116573?v=4)](https://github.com/xenon87 "xenon87 (2 commits)")[![pb30](https://avatars.githubusercontent.com/u/259602?v=4)](https://github.com/pb30 "pb30 (2 commits)")[![askdkc](https://avatars.githubusercontent.com/u/7894265?v=4)](https://github.com/askdkc "askdkc (1 commits)")[![peterfox](https://avatars.githubusercontent.com/u/1716506?v=4)](https://github.com/peterfox "peterfox (1 commits)")[![trippo](https://avatars.githubusercontent.com/u/497169?v=4)](https://github.com/trippo "trippo (1 commits)")[![butschster](https://avatars.githubusercontent.com/u/773481?v=4)](https://github.com/butschster "butschster (1 commits)")[![krishnahimself](https://avatars.githubusercontent.com/u/19906424?v=4)](https://github.com/krishnahimself "krishnahimself (1 commits)")

### Embed Badge

![Health badge](/badges/webninjjacoder-open-ai-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/webninjjacoder-open-ai-laravel/health.svg)](https://phpackages.com/packages/webninjjacoder-open-ai-laravel)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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