PHPackages                             dv-team/openai-chatgpt-api - 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. dv-team/openai-chatgpt-api

ActiveLibrary[API Development](/categories/api)

dv-team/openai-chatgpt-api
==========================

A PHP client for OpenAI's ChatGPT API

1.0(3w ago)0637MITPHPPHP &gt;= 8.1CI passing

Since Jan 9Pushed 3w agoCompare

[ Source](https://github.com/dv-team/php-openai-chatgpt-api)[ Packagist](https://packagist.org/packages/dv-team/openai-chatgpt-api)[ RSS](/packages/dv-team-openai-chatgpt-api/feed)WikiDiscussions main Synced 2w ago

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

OpenAI ChatGPT API Client for PHP
=================================

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

Lightweight PHP client for OpenAI's Responses API.

Features
--------

[](#features)

- Low-level `ChatGPT` client for single Responses API requests
- Stateful `GPTConversation` with context management
- Bounded multi-round tool execution
- PHP callable and manually defined function tools
- Hosted web search
- JSON Schema responses with local validation
- Serializable and resumable conversation sessions
- Prompt-cache configuration and usage metrics
- Image and custom attachment inputs
- Text-to-speech output
- Pluggable PSR-18 HTTP transport

Requirements and installation
-----------------------------

[](#requirements-and-installation)

The library requires PHP 8.1 or newer and the extensions listed in `composer.json`.

Install the package with `composer require dv-team/openai-chatgpt-api`.

Applications must provide an HTTP transport. The bundled `Psr18HttpClient`adapter accepts a PSR-18 client and PSR-17 request and stream factories.

Developer documentation
-----------------------

[](#developer-documentation)

- [Getting started and low-level requests](docs/getting-started.md)
- [Conversations, serialization, restoration, and prompt caching](docs/conversations.md)
- [Attachments and custom attachment serialization](docs/attachments.md)
- [Structured JSON responses](docs/structured-responses.md)
- [Tool calling](docs/tool-calling.md)
- [Web search](docs/web-search.md)
- [Text to speech](docs/text-to-speech.md)
- [Models and reasoning](docs/models-and-reasoning.md)
- [Executable examples](examples/README.md)

All detailed code examples live in `docs/` or `examples/`. The README remains a compact project and documentation index.

API overview
------------

[](#api-overview)

### `ChatGPT`

[](#chatgpt)

`DvTeam\ChatGPT\ChatGPT` is the stateless, low-level client. The caller supplies the complete context for one API request and receives a `ChatResponse`. `ChatGPT` does not retain context or execute requested tools.

### `GPTConversation`

[](#gptconversation)

`DvTeam\ChatGPT\GPTConversation` owns a conversation context, appends model responses, executes registered PHP tools, and records their results.

`step()` performs one API request. `runUntilResponse()` continues through tool rounds until a visible response is produced or its configured step limit is reached.

Complete sessions can be persisted with `toArray()` or `toJson()` and restored with `fromArray()` or `fromJson()`. Runtime dependencies and the currently available tools are injected during restoration.

Running the executable examples
-------------------------------

[](#running-the-executable-examples)

Set `OPENAI_API_KEY`, install development dependencies with `composer install`, and follow the commands in [the examples index](examples/README.md).

Development
-----------

[](#development)

Run the unit tests with `composer test`.

Run static analysis with `composer run phpstan`.

Notes
-----

[](#notes)

- The library uses the Responses API input format.
- JSON Schema responses are validated with `opis/json-schema`.
- A custom HTTP adapter must implement `HttpPostInterface` and return an `HttpResponse`.
- `ChatResponse::firstChoice()` returns the first response choice.

Maintenance
-----------

[](#maintenance)

Whenever new functionality is added, update both `README.md` and `AGENTS.md` so human-facing and agent-facing documentation stay aligned.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance94

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

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

26d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cf998d17114530b943a1e99eb63b62ec349c0546c92eb5794e33141ad02ed434?d=identicon)[dv-team](/maintainers/dv-team)

---

Top Contributors

[![rkrx](https://avatars.githubusercontent.com/u/5672982?v=4)](https://github.com/rkrx "rkrx (58 commits)")[![nf-digiV](https://avatars.githubusercontent.com/u/201922785?v=4)](https://github.com/nf-digiV "nf-digiV (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dv-team-openai-chatgpt-api/health.svg)

```
[![Health](https://phpackages.com/badges/dv-team-openai-chatgpt-api/health.svg)](https://phpackages.com/packages/dv-team-openai-chatgpt-api)
```

###  Alternatives

[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.6k2.2M145](/packages/mcp-sdk)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103574.3k69](/packages/friendsoftypo3-content-blocks)[pristas-peter/wp-graphql-gutenberg

Query gutenberg blocks with wp-graphql

305113.7k1](/packages/pristas-peter-wp-graphql-gutenberg)[uma/json-rpc

a JSON-RPC 2.0 server

3760.3k2](/packages/uma-json-rpc)[cpsit/project-builder

Composer package to create new projects from project templates

2640.2k5](/packages/cpsit-project-builder)[carsdotcom/laravel-json-schema

Json Schema validation for Laravel projects

1045.1k8](/packages/carsdotcom-laravel-json-schema)

PHPackages © 2026

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