Download the PHP package marcino0o/openai without Composer
On this page you can find all versions of the php package marcino0o/openai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package openai
OpenAI PHP SDK (by @marcino0o)
A lightweight, modern PHP (≥ 8.4) wrapper for the OpenAI API. Focused on simplicity and rapid integration for Chat Completions, with growing support for other endpoints.
Table of Contents
- Requirements
- Installation
- Quick Start
- Configuration
-
Usage
- Chat Completions – Basics
- System Role / Messages
- Model Selection
- Images
- Audio
- Moderations
- Supported Endpoints
- Error Handling
- Retry / Timeout / Streaming
- Logging & Telemetry
- Testing
- Contributing
- Versioning
- License
- FAQ
Requirements
- PHP 8.4+
- Composer
Installation
From Packagist
Quick Start
Configuration
- API key: via constructor or
OPENAI_API_KEYenv var. - Default model: configurable via
OPENAI_MODELor passed per request. - Timeouts/Retry: basic support (advanced retry middleware planned).
Usage
Chat Completions – Basics
Example response (truncated):
System Role / Messages
Example response (truncated):
Model Selection
Example response metadata:
Chat Completions – Advanced options
Images
Example response (truncated):
Audio
Example response:
Moderations
Example response:
Supported Endpoints
| Endpoint | Status | Notes |
|---|---|---|
| Chat Completions | ✅ Stable | Primary focus |
| Images (generation/edit) | ⚠️ Experimental | API subject to change |
| Audio (STT/TTS) | ⚠️ Experimental | Partial support |
| Embeddings | ⏳ Planned | Not yet implemented |
| Moderations | ⚙️ Beta | Basic support present |
| Files / Fine-tuning | ⏳ Planned | Not yet implemented |
| Assistants / Realtime / Agents | ⏳ Planned | Upcoming |
Error Handling
Wrap calls in try/catch blocks:
Retry / Timeout / Streaming
- Timeouts – configurable via HTTP client.
- Retry – exponential backoff (planned in upcoming release).
- Streaming – future
stream()API for live token events.
Logging & Telemetry
- Optional PSR-3 logger.
- Mask sensitive info (e.g., API keys, full prompts).
Testing
Run quality checks locally:
Note: Integration tests use mocked HTTP responses and do not require a live OpenAI API request.
Contributing
Contributions welcome!
- Documentation, examples, FAQ.
- Tests (SSE parsing, error mapping, retries).
- Embeddings/Moderations refinements.
- Retry middleware with exponential backoff.
Workflow:
- Fork → feature branch → PR with examples.
- CI (GitHub Actions) runs PHPUnit on PHP 8.4.
Versioning
- Semantic Versioning (SemVer).
- Breaking changes possible until
v1.0.0. - See
CHANGELOG.mdafter first release.
License
MIT
FAQ
Does it support streaming?
Streaming API planned (stream() returning partial deltas).
Which models can I use?
Use values from Openai\Model, e.g. gpt-5, gpt-4.1, gpt-4.1-mini, o3, o4-mini, gpt-4o, gpt-4o-mini, omni-moderation-latest, gpt-4o-mini-transcribe.
Is it production-ready? Yes for small/medium workloads. For heavy production, enable retry logic, monitoring, and pin a stable release.