client
⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
What is client?
⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
Overview of client
What it is
OpenAI PHP is a community-maintained PHP API client that allows you to interact with the OpenAI API. It requires PHP 8.2+ and is distributed via Composer.
Key features
- Provides a PHP client for the OpenAI API, supporting resources such as Models, Responses, Conversations, Containers, Skills, Agents, Vaults, Chat, Audio, Embeddings, Files, FineTuning, Decisions, Moderations, Images, Vector Stores, Batches, and Realtime Ephemeral Keys.
- Supports legacy resources (Completions) and deprecated resources (Assistants, Threads, FineTunes, Edits).
- Allows configuration of API key, organization, project, base URI, HTTP client, custom headers, query parameters, and stream handler.
- Includes a factory method for creating a customized client instance.
- Provides methods for listing, retrieving, and deleting models.
- Supports creating responses with tools such as web search preview, function calls, and hosted shell/skills.
Use cases
- Building PHP applications that need to generate text or JSON outputs using OpenAI models.
- Integrating OpenAI's API into existing PHP projects for tasks like chat, audio processing, embeddings, file handling, fine-tuning, moderation, image generation, and vector store management.
- Creating custom workflows that call external functions or use built-in tools like web search or file search.
Getting started
bashcomposer require openai-php/clientEnsure the php-http/discovery plugin is allowed or install a PSR-18 client manually:bashcomposer require guzzlehttp/guzzleThen use the client:php$yourApiKey = getenv('YOUR_API_KEY');$client = OpenAI::client($yourApiKey);$response = $client->responses()->create([ 'model' => 'gpt-4o', 'input' => 'Hello!',]);echo $response->outputText; // Hello! How can I assist you today?
License and pricing
The license is MIT. The package is open source and community-maintained.
Based on the project's public README and repository metadata.