-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
#285Add Auto function execution16 comments · 2023-12-04#198Undefined array key "content" (MS OpenAI Content Filtering issue)8 comments · 2023-08-28#545[Bug]: CreateStreamedResponse fails with custom models that return sources without choices7 comments · 2025-04-02#719Support for the new Prompts API (successor to deprecated Assistants API)6 comments · 2025-12-04#717[Bug]: Undefined array key "choices" in CreateStreamedResponse.php when using createStreamed()6 comments · 2025-11-25#568[Bug]: Warning: undefined array key 'id' using chat()4 comments · 2025-04-27#727[Bug]: Undefined array key "output" in D:\XXX\vendor\openai-php\client\src\Responses\Responses\CreateResponse.php on line 1163 comments · 2026-01-06#644[suggest] Some third-party models Response do not have 'object' and 'model'3 comments · 2025-08-14
Discussions
#690Gemini/Other Model's Support1 comments · 2025-09-28#675fix(OpenA): add 'web_search' as valid tool choice for Response API(#665)1 comments · 2025-09-04#655OpenAI Conversation State API2 comments · 2025-08-25#647Responses API, function calling example.3 comments · 2025-08-16#613How to use the AudioTestResource when faking out a response during testing1 comments · 2025-06-22#611How to use web search tool?1 comments · 2025-06-20#605Fluent Builders 💡0 comments · 2025-06-16#589Is realtime API available in openai-php? (Conversational Experiences)2 comments · 2025-05-28
Latest release
v0.22.0 v0.22.0 2026-10-31What'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/