openai-php /client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.

★ 5,835⑂ 682👁 81⑃ 404● 367▤ 48
PHPMITCreated 2022-09-25
下载:v0.22.0v0.22.0 ↓0.22.02026-10-31
-2
日增长
5,835
stars
682
forks
81
watchers
404
prs
367
issues
48
releases

README

------
OpenAI PHP is a community-maintained PHP API client that allows you to interact with the Open AI API.

- Follow the creator Nuno Maduro:
    - YouTube: youtube.com/@nunomaduro — Videos every weekday
    - Twitch: twitch.tv/enunomaduro — Streams (almost) every weekday
    - Twitter / X: x.com/enunomaduro
    - LinkedIn: linkedin.com/in/nunomaduro
    - Instagram: instagram.com/enunomaduro
    - Tiktok: tiktok.com/@enunomaduro

If you or your business relies on this package, it's important to support the developers who have contributed their time and effort to create and maintain this valuable tool:

- Nuno Maduro: github.com/sponsors/nunomaduro
- Sandro Gehri: github.com/sponsors/gehrisandro
- Connor Tumbleson: github.com/sponsors/iBotPeaches

 Table of Contents
- Get Started
- Usage
  - Models Resource
  - Responses Resource
  - Conversations Resource
  - Conversations Items Resource
  - Containers Resource
  - Containers Files Resource
  - Skills Resource
  - Skills Versions Resource
  - Agents Resource
  - Agents Environments Resource
  - Agents Environments Templates Resource
  - Agents Environments Files Resource
  - Agents Sessions Resource
  - Agents Sessions Events Resource
  - Vaults Resource
  - Vaults Credentials Resource
  - Chat Resource
  - Audio Resource
  - Embeddings Resource
  - Files Resource
  - FineTuning Resource
  - Decisions Resource
  - Moderations Resource
  - Images Resource
  - Vector Stores Resource
  - Vector Stores Files Resource
  - Vector Stores File Batches Resource
  - Batches Resource
  - Realtime Ephemeral Keys
  - Completions Resource (legacy)
  - Assistants Resource (deprecated)
  - Thread Resource (deprecated)
  - Thread Messages Resource (deprecated)
  - Thread Runs Resource (deprecated)
  - Thread Runs Steps Resource (deprecated)
  - FineTunes Resource (deprecated)
  - Edits Resource (deprecated)
- Meta Information
- Troubleshooting
- Testing
- [Webhooks][webhooks]
- Services
  - Azure

 Get Started

 Requires PHP 8.2+

First, install OpenAI via the Composer package manager:

bash
composer require openai-php/client


Ensure that the php-http/discovery composer plugin is allowed to run or install a client manually if your project does not already have a PSR-18 client integrated.
bash
composer require guzzlehttp/guzzle


Then, interact with OpenAI's API:

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?


If necessary, it is possible to configure and create a separate client.

php
$yourApiKey = getenv('YOUR_API_KEY');

$client = OpenAI::factory()
    -withApiKey($yourApiKey)
    -withOrganization('your-organization') // default: null
    -withProject('Your Project') // default: null
    -withBaseUri('openai.example.com/v1') // default: api.openai.com/v1
    -withHttpClient($httpClient = new \GuzzleHttp\Client([])

Top issues

Discussions

Latest release

v0.22.0 v0.22.0 2026-10-31
What's Changed
 Fix missing chunking strategy in vector store file responses by @midhunmonachan in https://github.com/openai-php/client/pull/805
 fix(OpenAI): trim streamed response data before decoding- 9 by @e4se in https://github.com/openai-php/client/pull/806
 fix(OpenAI): handle undocumented text web search results- 10 by @e4se in https://github.com/openai-php/client/pull/807
 feat(OpenAI): add Skills API by @heyzainali in https://github.com/openai-php/client/pull/808
 feat(OpenAI): add shell tool and skill attachments support by @omitech in https://github.com/openai-php/client/pull/

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON