OpenAI PHP

A community-maintained PHP API client for interacting with the full OpenAI API.

SDK
Composer
vv0.20.1
5,825stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
85/100Excellent
Development Activity84
Maintenance84
Community80
Maturity52
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
86/100Excellent
Architecture88
Code Quality90
Innovation80
Learning Curve82

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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search