openai-php/client
Community PHP SDK for OpenAI API calls, structured responses, and SSE streaming
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & 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.
PHP 8.2+ backends that need structured OpenAI Responses, streaming output, or remote conversation state with minimal custom transport code.
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.
Quick Start & Installation
composer require openai-php/client
Comparison vs. Top LLMs & Inference Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| client ★ | 5.8k | +1 | PHP | MIT | Community PHP SDK for OpenAI API calls, structured responses, and SSE streaming |
| openai-python | 32.3k | +58 | Python | Apache-2.0 | Typed sync and async Python SDK for OpenAI API calls, streaming, and Realtime. |
| openai-node | 11.3k | +14 | TypeScript | Apache-2.0 | Generated TypeScript SDK for integrating the hosted OpenAI API |
| transformers | 169.6k | +337 | Python | Apache-2.0 | A 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.
curl -sL https://repoforai.com/repo/openai-php/client.md
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?
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?
Can I use it commercially and still host my own application?
When is direct HTTP a better choice?
Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
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