PHPackages                             laswitchtech/php-openai - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. laswitchtech/php-openai

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

laswitchtech/php-openai
=======================

OpenAI Library for PHP Applications

v1.0.3(3y ago)013GPL-3.0-onlyPHP

Since Mar 1Pushed 3y ago1 watchersCompare

[ Source](https://github.com/LouisOuellet/php-openai)[ Packagist](https://packagist.org/packages/laswitchtech/php-openai)[ RSS](/packages/laswitchtech-php-openai/feed)WikiDiscussions stable Synced today

READMEChangelog (3)DependenciesVersions (4)Used By (0)

[![GitHub repo logo](/dist/img/logo.png)](/dist/img/logo.png)

phpOpenAI
=========

[](#phpopenai)

[![License](https://camo.githubusercontent.com/1cf2f0c391b553817677d5ee72a9fc8074cc19d5ed38adaa4e5fdcc829dc1925/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4c6f7569734f75656c6c65742f7068702d6f70656e61693f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/1cf2f0c391b553817677d5ee72a9fc8074cc19d5ed38adaa4e5fdcc829dc1925/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4c6f7569734f75656c6c65742f7068702d6f70656e61693f7374796c653d666f722d7468652d6261646765)[![GitHub repo size](https://camo.githubusercontent.com/905c72dc9064e1dbcae596e2bbd6e00c3748acce4196bd1f1b8af5a52982c3aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f4c6f7569734f75656c6c65742f7068702d6f70656e61693f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562)](https://camo.githubusercontent.com/905c72dc9064e1dbcae596e2bbd6e00c3748acce4196bd1f1b8af5a52982c3aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f4c6f7569734f75656c6c65742f7068702d6f70656e61693f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562)[![GitHub top language](https://camo.githubusercontent.com/d78f436a15b0142520afdb38675f19f8c7c636bd858350dd13a8b0e00575da0f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f4c6f7569734f75656c6c65742f7068702d6f70656e61693f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/d78f436a15b0142520afdb38675f19f8c7c636bd858350dd13a8b0e00575da0f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f4c6f7569734f75656c6c65742f7068702d6f70656e61693f7374796c653d666f722d7468652d6261646765)[![Version](https://camo.githubusercontent.com/99dc52674e47c1d316f24770d994cf8c3d32f447bfed1624822371018707ef19/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4c6f7569734f75656c6c65742f7068702d6f70656e61693f6c6162656c3d56657273696f6e267374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/99dc52674e47c1d316f24770d994cf8c3d32f447bfed1624822371018707ef19/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4c6f7569734f75656c6c65742f7068702d6f70656e61693f6c6162656c3d56657273696f6e267374796c653d666f722d7468652d6261646765)

Features
--------

[](#features)

- Easy to use OpenAI cURL Library

Why you might need it
---------------------

[](#why-you-might-need-it)

If you are looking for an easy way to integrate OpenAI in your project. This PHP Class is for you.

Can I use this?
---------------

[](#can-i-use-this)

Sure!

License
-------

[](#license)

This software is distributed under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html) license. Please read [LICENSE](LICENSE) for information on the software availability and distribution.

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

[](#requirements)

- PHP &gt;= 5.6.0

Security
--------

[](#security)

Please disclose any vulnerabilities found responsibly – report security issues to the maintainers privately.

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

[](#installation)

Using Composer:

```
composer require laswitchtech/php-openai
```

How do I use it?
----------------

[](#how-do-i-use-it)

In this documentations, we will use a table called users for our examples.

### Example

[](#example)

#### Initiate phpOpenAI

[](#initiate-phpopenai)

```
//Import phpOpenAI class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\phpOpenAI\phpOpenAI;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Initiate phpOpenAI
$phpOpenAI = new phpOpenAI('YOUR_API_KEY');
```

#### Completions

[](#completions)

```
//Import phpOpenAI class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\phpOpenAI\phpOpenAI;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Initiate phpOpenAI
$phpOpenAI = new phpOpenAI('YOUR_API_KEY');

//Request
$phpOpenAI->completions([
  'model' => 'text-davinci-003',
  'prompt' => 'Say this is a test',
  'temperature' => 0,
  'max_tokens' => 7,
  'top_p' => 1,
  'n' => 1,
  'stream' => false,
  'logprobs' => null,
  'stop' => '\n',
]); // Returns an array
```

#### Edits

[](#edits)

```
//Import phpOpenAI class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\phpOpenAI\phpOpenAI;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Initiate phpOpenAI
$phpOpenAI = new phpOpenAI('YOUR_API_KEY');

//Request
$phpOpenAI->edits([
  'model' => 'text-davinci-edit-001',
  'input' => 'What day of the wek is it?',
  'instruction' => 'Fix the spelling mistakes',
]); // Returns an array
```

#### Moderations

[](#moderations)

```
//Import phpOpenAI class into the global namespace
//These must be at the top of your script, not inside a function
use LaswitchTech\phpOpenAI\phpOpenAI;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Initiate phpOpenAI
$phpOpenAI = new phpOpenAI('YOUR_API_KEY');

//Request
$phpOpenAI->moderations([
  'model' => 'text-moderation-stable',
  'input' => 'I want to kill them.',
]); // Returns an array
```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

3

Last Release

1219d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25933907?v=4)[Louis Ouellet](/maintainers/LouisOuellet)[@LouisOuellet](https://github.com/LouisOuellet)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[topthink/think-captcha

captcha package for thinkphp

117970.1k74](/packages/topthink-think-captcha)[laravel-frontend-presets/now-ui-dashboard

Laravel 11.x Front-end preset for now ui dashboard

22318.5k](/packages/laravel-frontend-presets-now-ui-dashboard)

PHPackages © 2026

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