PHPackages                             webboy/open-ai-api-client - 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. webboy/open-ai-api-client

ActiveLibrary[API Development](/categories/api)

webboy/open-ai-api-client
=========================

PHP client for the OpenAI API

1.1.2(3y ago)524541MITPHPPHP ^8.0

Since Mar 19Pushed 3y ago10 watchersCompare

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

READMEChangelog (3)Dependencies (5)Versions (7)Used By (1)

PHP OpenAI API Client
=====================

[](#php-openai-api-client)

A simple community-maintained PHP client library for interacting with the OpenAI API. This package provides an easy way to use OpenAI's GPT models for tasks such as text generation and completion.

Please note that this is an unofficial library.

This library is handy because it returns back a raw response as array which can then be used by any kind of adapter class.

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

[](#requirements)

- PHP 8.0 or higher
- Guzzle HTTP client

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

[](#installation)

You can install the package via Composer:

```
composer require webboy/open-ai-api-client
```

Usage examples
--------------

[](#usage-examples)

First, create an instance of the `Endpoint` classes with your API key:

```
require_once('vendor/autoload.php');

use Dotenv\Dotenv;
use Webboy\OpenAiApiClient\Endpoints\OpenAICompletions;
use Webboy\OpenAiApiClient\Exceptions\OpenAIClientException;

$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();

$apiKey = $_ENV['OPENAI_API_KEY'];

$client = new OpenAICompletions($apiKey);

$options['model']   = 'text-davinci-003';
$options['prompt']  = 'What time is it?';

try {
    print_r($client->create($options));
} catch (OpenAIClientException $exception) {
    die('OpenAI error occured: '.$exception->getMessage());
}
```

The above code will generate something like this:

```
Array
(
    [id] => cmpl-6wAQB0aPhvbxMAyIdz98z8jpPeKdq
    [object] => text_completion
    [created] => 1679321103
    [model] => text-davinci-003
    [choices] => Array
        (
            [0] => Array
                (
                    [text] =>It is 6:25 PM.
                    [index] => 0
                    [logprobs] =>
                    [finish_reason] => stop
                )
        )
    [usage] => Array
        (
            [prompt_tokens] => 5
            [completion_tokens] => 9
            [total_tokens] => 14
        )
)

```

Testing
-------

[](#testing)

Endpoint classes are created to accept HTTP client as a parameter, which enables mocking tests to be performed without making real API calls. If you need to make real API calls, feel free to create a testuit. To run PHPUnit tests:

```
./vendor/bin/phpunit
```

License
-------

[](#license)

The PHP OpenAI API Client is open-sourced software licensed under the MIT license.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity54

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

Total

6

Last Release

1148d ago

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/webboy-open-ai-api-client/health.svg)

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

###  Alternatives

[netflie/whatsapp-cloud-api

The first PHP SDK to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

640431.7k4](/packages/netflie-whatsapp-cloud-api)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[hardcastle/xrpl_php

PHP SDK / Client for the XRP Ledger

129.7k5](/packages/hardcastle-xrpl-php)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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