explaingit

openai-php/client

5,778PHPAudience · developerComplexity · 2/5Setup · easy

TLDR

A community PHP library for calling the OpenAI API, covering chat, images, audio, embeddings, fine-tuning, and more, installable with one Composer command and compatible with Azure's OpenAI endpoint.

Mindmap

mindmap
  root((repo))
    What it does
      OpenAI API client
      PHP integration
      Azure compatible
    Tech Stack
      PHP
      Composer
      OpenAI API
    Features
      Chat and text
      Image generation
      Audio transcription
      Embeddings
      Fine-tuning
    Use Cases
      Chatbot in PHP
      Content moderation
      Document search
      Azure deployment
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Send messages to GPT-4 and other OpenAI models from a PHP application with just a few lines of code.

USE CASE 2

Generate images, transcribe audio, and run content moderation checks from PHP using OpenAI's API.

USE CASE 3

Build a multi-turn chat application in PHP using the Conversations API to maintain conversation history.

USE CASE 4

Point the library at an Azure OpenAI endpoint for teams using Microsoft Azure's hosted AI models.

Tech stack

PHPComposerOpenAI API

Getting it running

Difficulty · easy Time to first run · 5min

Requires a paid OpenAI API key and PHP 8.2 or newer.

The explanation does not mention the license terms.

In plain English

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.

Copy-paste prompts

Prompt 1
Install openai-php/client with Composer and show me the minimal PHP code to send a message to GPT-4 and print the response.
Prompt 2
Using openai-php/client, write a PHP function that checks user-submitted text with OpenAI's moderation endpoint and returns whether it's safe to display.
Prompt 3
How do I configure openai-php/client to use my Azure OpenAI endpoint instead of OpenAI's default API URL?
Prompt 4
Write a PHP script using openai-php/client that generates an image from a text prompt using DALL-E and saves it to a local file.
Prompt 5
Show me how to write unit tests for code that uses openai-php/client without making real API calls each time the tests run.
Open on GitHub → Explain another repo

← openai-php on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.