# Repository Briefing: openai-php/client
> Source: https://repoforai.com/repo/openai-php/client (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/openai-php/client
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: PHP
- **License**: MIT
- **Engineering Health**: A+ (95/100 · Maintenance 35/35 · Adoption 20/25 · Releases 20/20 · License 20/20)
- **Latest Release**: v0.22.0 (2026-10-31) — https://github.com/openai-php/client/releases
- **Review Snapshot**: 2026-12-04
- **Deployment / Stack Signals**: API
- **Momentum**: 5,834 ★ total (+0 24h / +1 7d) · 679 forks
- **Topics**: `api`, `client`, `codex`, `gpt-3`, `gpt-4`, `gpt-5`, `language`, `natural`, `openai`, `php`, `processing`, `sdk`
- **When to Use**: 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.

## Overview
```text
### 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.
```

## Key Capabilities
```text
- 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.
```

## Quick Start / Clone
```bash
composer require openai-php/client
```
