PHPackages                             sgraaf/chatgpt-php - 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. sgraaf/chatgpt-php

AbandonedArchivedLibrary[API Development](/categories/api)

sgraaf/chatgpt-php
==================

A convenient PHP wrapper for the OpenAI ChatGPT API.

0.1.0(3y ago)06.5k—0%[1 PRs](https://github.com/sgraaf/chatgpt-php/pulls)MITPHP

Since Mar 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/sgraaf/chatgpt-php)[ Packagist](https://packagist.org/packages/sgraaf/chatgpt-php)[ Docs](https://github.com/sgraaf/chatgpt-php)[ RSS](/packages/sgraaf-chatgpt-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

ChatGPT PHP
===========

[](#chatgpt-php)

[![Packagist Version](https://camo.githubusercontent.com/538004f03ecb27b2e33a379758e42070bd878034110689e8aab1c556d87296ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7367726161662f636861746770742d706870)](https://packagist.org/packages/sgraaf/chatgpt-php)[![Packagist PHP Version](https://camo.githubusercontent.com/1deaa8ee5e6bb28ad9aef32ffb7af0db2b209103412676228502c41d3dc2c8ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f7367726161662f636861746770742d7068702f706870)](https://img.shields.io/packagist/dependency-v/sgraaf/chatgpt-php/php)[![pre-commit.ci status](https://camo.githubusercontent.com/650b60c0d3cea3266356ff7fc794a973e1d0ce2c749fd94cba030956343c103e/68747470733a2f2f726573756c74732e7072652d636f6d6d69742e63692f62616467652f6769746875622f7367726161662f636861746770742d7068702f6d61696e2e737667)](https://results.pre-commit.ci/latest/github/sgraaf/chatgpt-php/main)[![Packagist License](https://camo.githubusercontent.com/e08b4b8c962049b9988a714569dde49738471fe443e60db1fddca66018f7241d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7367726161662f636861746770742d706870)](./LICENSE)

A convenient PHP wrapper for the OpenAI ChatGPT API.

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

[](#installation)

You can install ChatGPT PHP via [Composer](https://getcomposer.org/):

```
composer require sgraaf/chatgpt-php
```

Usage
-----

[](#usage)

### Initialize the client

[](#initialize-the-client)

```
// initialize the client
$client = new ChatGPT\Client('YOUR_OPENAI_API_KEY');
```

#### Use a custom *system message*

[](#use-a-custom-system-message)

```
// initialize the client
$client = new ChatGPT\Client('YOUR_OPENAI_API_KEY', system_message: 'You are a helpful assistant that translates English to French.');
```

### Start a conversation

[](#start-a-conversation)

```
// provide an instruction
$message = $client->chat('Who won the world series in 2020?');
var_dump($message);
// string(53) "The Los Angeles Dodgers won the World Series in 2020."

// continue the conversation
$message = $client->chat('Where was it played?');
var_dump($message);
// string(116) "The 2020 World Series was played in Arlington, Texas at the Globe Life Field, the home stadium of the Texas Rangers."
```

### View the conversation history

[](#view-the-conversation-history)

```
var_dump($client->messages);
// array(5) {
//   [0]=>
//   array(2) {
//     ["role"]=>
//     string(6) "system"
//     ["content"]=>
//     string(28) "You are a helpful assistant."
//   }
//   [1]=>
//   array(2) {
//     ["role"]=>
//     string(4) "user"
//     ["content"]=>
//     string(33) "Who won the world series in 2020?"
//   }
//   [2]=>
//   array(2) {
//     ["role"]=>
//     string(9) "assistant"
//     ["content"]=>
//     string(53) "The Los Angeles Dodgers won the World Series in 2020."
//   }
//   [3]=>
//   array(2) {
//     ["role"]=>
//     string(4) "user"
//     ["content"]=>
//     string(20) "Where was it played?"
//   }
//   [4]=>
//   array(2) {
//     ["role"]=>
//     string(9) "assistant"
//     ["content"]=>
//     string(116) "The 2020 World Series was played in Arlington, Texas at the Globe Life Field, the home stadium of the Texas Rangers."
//   }
// }
```

### Clear the conversation history

[](#clear-the-conversation-history)

```
// clear the conversation history
$client->clear();

var_dump($client->messages);
// array(1) {
//   [0]=>
//   array(2) {
//     ["role"]=>
//     string(6) "system"
//     ["content"]=>
//     string(28) "You are a helpful assistant."
//   }
// }
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

1168d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8904453?v=4)[Steven van de Graaf](/maintainers/sgraaf)[@sgraaf](https://github.com/sgraaf)

---

Top Contributors

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

---

Tags

phpapiclientsdkopenaichatbotChatGpt

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sgraaf-chatgpt-php/health.svg)

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

###  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/laravel

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

3.7k7.6M74](/packages/openai-php-laravel)[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

47073.9k5](/packages/deepseek-php-deepseek-php-client)

PHPackages © 2026

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