← Back to Leaderboard
Copenai-php

openai-php/client

Community PHP SDK for OpenAI API calls, structured responses, and SSE streaming

View on GitHub ↗
AI FrameworkQuickstart ↓
Engineering Health (Methodology)
A+ · 95/100
Maintenance Activity
● Updated 5d ago
Latest Release
v0.22.0
Commercial License Check
MIT · Commercial Friendly

Automated SPDX check for reference only — not legal advice. Disclaimer

Maintenance35/35
Fork Adoption20/25
Release Cadence20/20
License Clarity20/20
API
Total Stars
★ 5,834
24h Growth
+0
7d Growth
+1
Forks
679

GitHub Star History

Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.

openai-php/client Star History (2022-09-25 - 2026-12-04) ALL-TIME STAR HISTORY (2022-09 – 2026-12) +5.8k in 1531d · avg +4/day 6.2k 3.1k 0 2022-09-25: ★ 212022-12-31: ★ 9002023-04-08: ★ 2,1272023-07-15: ★ 2,8252023-10-21: ★ 3,3072024-01-27: ★ 3,8602024-05-04: ★ 4,1902024-08-10: ★ 4,5012024-11-16: ★ 4,8022025-02-22: ★ 5,0322025-05-31: ★ 5,2572025-09-06: ★ 5,4332025-12-13: ★ 5,5962026-03-21: ★ 5,6892026-06-27: ★ 5,7702026-10-03: ★ 5,8212026-12-04: ★ 5,834 ★ 5.8k 2022-09 2024-10 2026-12

Evidence-Backed Technical Brief

AI Deep Review

Architecture & Core Mechanics

openai-php/client is a community-maintained Composer SDK for calling the OpenAI API from PHP, not an inference engine. OpenAI::client() is the short path; OpenAI::factory() configures credentials, organization, project, base URI, headers, and query parameters. Resource methods such as responses() and conversations() accept PHP arrays and return structured response objects that can be converted back with toArray().

The transport uses a discovered or explicitly injected PSR-18 HTTP client. A separate stream handler can configure the underlying transport to deliver an unbuffered response; streamed methods expose iterable server-sent events (SSE). withHttpHeaders() creates a client with case-insensitive header overrides while reusing the HTTP client and stream handler, so request-specific correlation IDs do not change shared defaults.

Key Capabilities & Differentiators

The Responses API surface accepts text and image inputs, supports text and JSON outputs, and exposes aggregated outputText alongside individual output items and token usage. It handles custom function tools and built-in web or file search, subject to endpoint and model support. Calls cover creation, retrieval, cancellation of background responses, deletion, input-item listing, and a separate input-token count. Both creation and retrieval have SSE variants.

Conversations expose create, retrieve, and delete operations, plus item creation, listing, retrieval, and deletion. compact() produces an encrypted item for reuse in a later request rather than resending the full history. Other exposed resources include model listing and metadata retrieval and container creation and listing for Code Interpreter. These are remote API capabilities, not PHP-side model or sandbox runtimes.

Trade-offs & Limitations

Compared with raw HTTP, the SDK gives PHP teams resource-oriented methods, structured response access, and decoded stream events instead of hand-written request and parsing code. The trade-off is a compatibility layer that must keep pace with API changes. The v0.22.0 notes include a fix for an undocumented text web-search case. A configurable base URI helps with endpoint routing, but does not guarantee that another provider matches OpenAI's request, response, tool, and event schemas.

Inference latency, usage charges, and rate limits remain properties of the remote service. The application still needs its own timeout and retry policy, and a streaming path must avoid buffering if clients are to see partial output promptly. The MIT license permits commercial use of the library, but does not change the remote API's terms or make a remote integration suitable for offline or data-local workloads.

Hardware & Deployment Guide

Run PHP 8.2+ and install with composer require openai-php/client. Allow the php-http/discovery Composer plugin or explicitly supply a PSR-18 implementation; Guzzle is the documented example. Load the API key from the application environment and provide network access to api.openai.com/v1 or the configured endpoint. The SDK runs inside the PHP application; it does not require a separate inference deployment, GPU, or VRAM on the PHP host.

For streamed deployments, verify end-to-end buffering behavior and size PHP worker or connection capacity for concurrent, long-lived requests. v0.21.0 expanded the Responses API surface with programmatic tool calling and apply_patch; v0.22.0 trims streamed data before decoding and fixes a missing chunking strategy in vector-store file responses. Test the stream events and response fields your application depends on when upgrading.

Transport: PSR-18 client discovery or explicit injection, plus a separate streaming handler.
Request context: withHttpHeaders() applies case-insensitive header overrides without mutating the original client.
Responses: Text and image input, text and JSON output, aggregate outputText, and usage counters.
Streaming: createStreamed() and retrieveStreamed() expose SSE events for creation and retrieval.
Conversation state: Conversation and item operations, plus encrypted compaction output for a subsequent request.
Compatibility fixes: v0.22.0 trims streamed response data before decoding and fixes a missing chunking strategy in vector-store file responses.
Best For

PHP 8.2+ backends that need structured OpenAI Responses, streaming output, or remote conversation state with minimal custom transport code.

Skip If

You need offline or self-hosted inference, cannot send data to the selected endpoint, or need an API feature that the SDK does not yet expose.

Reviewed on 2026-12-04 · Grounded in GitHub README, root file tree & releasesMethodology

Quick Start & Installation

API
composer require openai-php/client

Comparison vs. Top LLMs & Inference Alternatives

Full comparison →
RepositoryStars7d TrendStackLicenseCore Positioning
client ★5.8k+1PHPMITCommunity PHP SDK for OpenAI API calls, structured responses, and SSE streaming
openai-python32.3k+58PythonApache-2.0Typed sync and async Python SDK for OpenAI API calls, streaming, and Realtime.
openai-node11.3k+14TypeScriptApache-2.0Generated TypeScript SDK for integrating the hosted OpenAI API
transformers169.6k+337PythonApache-2.0A PyTorch model-definition SDK for unified inference and training across modalit

AI Context Briefing (for Claude / Cursor / Windsurf)

Standardized architecture summary & quickstart commands ready to paste into coding agents.

Raw .md ↗
curl -sL https://repoforai.com/repo/openai-php/client.md

Embed Star History Chart & Badges in README.md

Full-history Star History SVGs and velocity cards on GitHub Camo: drop-in replacement for OSSInsight and Star History widgets.

openai-php/client Star History on RepoForAI

Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).

Frequently Asked Questions about client

How do I integrate the SDK with an existing PHP HTTP stack?

Use OpenAI::client() for a basic connection or OpenAI::factory() to inject a PSR-18 HTTP client such as Guzzle and configure the base URI, headers, or streaming handler. For per-request trace IDs, withHttpHeaders() returns a derived client that shares the existing HTTP client and stream handler without changing the original configuration.

Does the PHP host need a GPU, and what drives runtime overhead?

No GPU or dedicated VRAM is needed on the PHP host because the API endpoint runs inference. Size the application for concurrent requests, response sizes, and stream duration. If your PHP server assigns a worker to each request, a long-lived SSE stream can occupy that worker until the stream closes.

Can I use it commercially and still host my own application?

Yes. The MIT license permits commercial use; retain the required notices when redistributing the SDK. You can host the PHP application yourself, but this package does not self-host inference. API terms, data retention, and any data residency obligations must be evaluated separately for the endpoint you use.

When is direct HTTP a better choice?

Choose the SDK when you want resource methods, structured responses, and SSE decoding without implementing them yourself. Use direct HTTP when you need an endpoint or event shape that the SDK has not caught up with, or when a small integration needs only one call and you prefer to own the transport code.

Upstream README & Documentation

This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.

Maintaining openai-php/client? Pin to Homepage + competitor /alternatives pages with a custom Cloud/Demo CTA.Feature openai-php/client on Homepage & Alternatives ($19)
WEEKLY BREAKOUT DIGEST

Top 10 Breakout Open-Source AI Repos, Every Thursday

Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.

Zero spam · 1-click unsubscribe · Privacy Policy

Saved in your browser · Export Markdown RFC tables or jump into /vs compare