Send messages to GPT-4 and other OpenAI models from a PHP application with just a few lines of code.
Generate images, transcribe audio, and run content moderation checks from PHP using OpenAI's API.
Build a multi-turn chat application in PHP using the Conversations API to maintain conversation history.
Point the library at an Azure OpenAI endpoint for teams using Microsoft Azure's hosted AI models.
Requires a paid OpenAI API key and PHP 8.2 or newer.
This is a community-built PHP library that lets PHP applications talk to OpenAI's API. OpenAI is the company behind GPT-4 and other AI models, and their API lets developers send text or images to those models and get AI-generated responses back. This library handles all the technical details of making those API calls from PHP code, so you do not have to write the low-level networking yourself. Installing the library takes one terminal command using Composer, which is the standard package manager for PHP projects. Once installed, you point it at your OpenAI API key and start sending requests. The simplest case is just a few lines: create a client, send a message, get a reply. The library also supports more advanced configuration, such as pointing it at a custom server address instead of OpenAI's default one, adding custom HTTP headers, or swapping in a different HTTP client if your project already uses one. The library covers a wide range of OpenAI features. You can generate text responses, list or delete AI models, work with files, create and manage fine-tuned models, generate images, run moderation checks on text, create audio transcriptions, work with embeddings (numerical representations of text used in search and similarity tasks), and manage vector stores used for document search. It also supports the Responses and Conversations APIs for multi-turn chat interactions, and includes access to real-time session keys for live streaming use cases. Azure is supported as a service backend, meaning teams already using Microsoft Azure's hosted version of OpenAI can point this same library at their Azure endpoint instead. The README includes a testing section covering how to write tests against the library without making real API calls each time. The library is maintained by a small group of contributors and is funded through GitHub sponsorships. It requires PHP version 8.2 or newer. The full README is longer than what was shown.
← openai-php on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.