OpenAI PHP
A community-maintained PHP API client for interacting with the full OpenAI API.
Repository Health
Technical Analysis
openai-php/client (OpenAI PHP) is a supercharged, community-maintained PHP SDK for the OpenAI API, created by Nuno Maduro and Sandro Gehri. It gives PHP applications a clean, typed interface to nearly the entire OpenAI platform.
It covers a broad set of resources, including chat and the Responses API, conversations, embeddings, images, audio, files, fine-tuning, moderations, vector stores, batches, and more, plus supporting features like webhooks and a testing fake. Built on PSR HTTP standards, it lets you plug in your own HTTP client.
What You Get
- Typed resources spanning chat, responses, conversations, embeddings, images, and audio
- Coverage of files, fine-tuning, moderations, vector stores, and batches
- A factory-based client supporting API keys, organizations, and custom base URIs
- PSR-18/PSR-17 foundation so you can bring any HTTP client implementation
- A built-in testing fake for asserting API interactions without real calls
Common Use Cases
- Adding chat, completion, or assistant features to a PHP or Laravel application
- Generating embeddings for semantic search and retrieval workflows
- Creating or moderating images and transcribing audio via the OpenAI API
- Managing files, fine-tuning jobs, and vector stores from PHP code
Under The Hood
Architecture - The library is organized under the OpenAI\ namespace. A Factory builds a Client that wires an HTTP transporter (using php-http/discovery to find a PSR-18 client) to a set of Resources, each mapping to an OpenAI API area. Requests are modeled as Actions/ValueObjects and responses as typed Response objects; a Testing namespace provides a fake client, and Webhooks parse inbound events.
Tech Stack - PHP ^8.2 built on PSR HTTP interfaces (psr/http-client, psr/http-message) with php-http/discovery and multipart-stream-builder. Dev tooling is modern and thorough: Pest for tests (with arch and type-coverage plugins), PHPStan, and Laravel Pint for style.
Code Quality - The project shows strong engineering practices: extensive typed value objects, a dedicated testing fake, Pest-based test suites including architecture and type-coverage checks, and PHPStan static analysis, all reflected in its high repo-health signals and large community.
API Design - The developer experience is a highlight: OpenAI::client($apiKey) yields a client whose resource methods read naturally (e.g. $client->chat()->create(…)), returning typed responses. Consistent naming across resources and a fluent factory keep boilerplate minimal.