PHPackages                             lyhiving/open-ai - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. lyhiving/open-ai

ActiveLibrary[API Development](/categories/api)

lyhiving/open-ai
================

OpenAI GPT-3 Api Client in PHP inorge SSL check

3.16(2y ago)026MITPHPPHP &gt;=7.4

Since Feb 7Pushed 2y agoCompare

[ Source](https://github.com/lyhiving/open-ai)[ Packagist](https://packagist.org/packages/lyhiving/open-ai)[ Docs](https://github.com/lyhiving/open-ai)[ GitHub Sponsors](https://github.com/orhanerday)[ RSS](/packages/lyhiving-open-ai/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (14)Used By (0)

OpenAI API Client in PHP
========================

[](#openai-api-client-in-php)

> ### ChatGPT API is currently supported, [click here](#chat-as-known-as-chatgpt-api) for the implementation introductions.
>
> [](#chatgpt-api-is-currently-supported-click-here-for-the-implementation-introductions)

*A message from creator,
Thank you for visiting the **@lyhiving/open-ai** repository! If you find this repository helpful or useful, we encourage you to **star** it on GitHub. Starring a repository is a way to show your support for the project. It also helps to increase the visibility of the project and to let the community know that it is valuable. Thanks again for your support and we hope you find the repository useful!

 Orhan*

[![Latest Version on Packagist](https://camo.githubusercontent.com/cb803f98ed4fa0b714a0d80589e20d789ba777dde95b466ebc250180f7a8f6a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c79686976696e672f6f70656e2d61692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lyhiving/open-ai)[![Total Downloads](https://camo.githubusercontent.com/16a44d7c45bb872e0c277a67bbcb4d2c0450a91f01f1ea420bf58139c1cb433a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c79686976696e672f6f70656e2d61692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lyhiving/open-ai)

[![lyhiving-open-ai-logo](./openai-elephpant.svg)](./openai-elephpant.svg)

Featured in
===========

[](#featured-in)

[![Jetbrains Blog](https://user-images.githubusercontent.com/22305274/222431781-86591161-ccd5-4889-bd80-97a0fd0fdf0d.png)](https://blog.jetbrains.com/phpstorm/2022/12/php-annotated-december-2022/#:~:text=lyhiving/open%2Dai%20%E2%80%93%20A%20PHP%20SDK%20for%20accessing%20the%20OpenAI%20GPT%2D3%20API)

[![Laravel News](https://user-images.githubusercontent.com/22305274/222430084-be097d59-e6bc-408d-8adb-7b751d5a05b2.png)](https://laravel-news.com/openai-sdk-for-php)

[![日思录](https://user-images.githubusercontent.com/22305274/222431699-f3a8a146-e27c-4fe3-8c93-1d762559752f.png)](http://tubring.cn/articles/59)

Comparison With Other Packages
==============================

[](#comparison-with-other-packages)

Project NameRequired PHP VersionDownloadsDescriptionType (Official / Community)Support**lyhiving/open-ai****PHP 7.4+**[![Total Downloads](https://camo.githubusercontent.com/16a44d7c45bb872e0c277a67bbcb4d2c0450a91f01f1ea420bf58139c1cb433a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c79686976696e672f6f70656e2d61692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lyhiving/open-ai)
**Most downloaded, forked, contributed, huge community supported, and used PHP SDK for OpenAI GPT-3 and DALL-E. It also supports chatGPT-like streaming.**CommunityAvailable, ([Community driven Discord Server](https://discord.gg/xpGUD528XJ) or personal mail )openai-***/c***\*tPHP 8.1+[![Total Downloads](https://camo.githubusercontent.com/20c6fe5413b5dfa3eadd1a55f55c3858aaa52f98d088ce5ea890aebb3956353e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f70657a61692d7068702f636c69656e74)](https://packagist.org/packages/opezai-php/client)OpenAI PHP API client.Community-
About this package
------------------

[](#about-this-package)

Fully open-source and secure community-maintained, PHP SDK for accessing the OpenAI GPT-3 API.

> #### For more information, you can read laravel news [blog post](https://laravel-news.com/openai-sdk-for-php).
>
> [](#for-more-information-you-can-read-laravel-news-blog-post)
>
> #### Free support is available. [Join our discord server](#join-our-discord-server)
>
> [](#free-support-is-available-join-our-discord-server)
>
> #### To get started with this package, you'll first want to be familiar with the [OpenAI API documentation](https://beta.openai.com/docs/introduction) and [examples](https://beta.openai.com/examples). Also you can get help from our discord channel that called [\#api-support](https://discord.gg/R9CpVUdqQR)
>
> [](#to-get-started-with-this-package-youll-first-want-to-be-familiar-with-the-openai-api-documentation-and-examples-also-you-can-get-help-from-our-discord-channel-that-called-api-support)

News
----

[](#news)

- lyhiving/open-ai added to community libraries php [section](https://beta.openai.com/docs/libraries/php).
- lyhiving/open-ai featured on [PHPStorm blog post](https://blog.jetbrains.com/phpstorm/2022/12/php-annotated-december-2022/#:~:text=lyhiving/open%2Dai%20%E2%80%93%20A%20PHP%20SDK%20for%20accessing%20the%20OpenAI%20GPT%2D3%20API), thanks JetBrains!

> Requires PHP 7.4+

Join our discord server
-----------------------

[](#join-our-discord-server)

[![Discord Banner 2](https://camo.githubusercontent.com/1f906f2edcd81710fb3dbc17a390bed71ec6edcf830fbabca9268486aa73a6da/68747470733a2f2f646973636f72646170702e636f6d2f6170692f6775696c64732f313034373037343537323438383431373333302f7769646765742e706e673f7374796c653d62616e6e657232)](https://camo.githubusercontent.com/1f906f2edcd81710fb3dbc17a390bed71ec6edcf830fbabca9268486aa73a6da/68747470733a2f2f646973636f72646170702e636f6d2f6170692f6775696c64732f313034373037343537323438383431373333302f7769646765742e706e673f7374796c653d62616e6e657232)

[Click here to join the Discord server](https://discord.gg/xpGUD528XJ)

Support this project
--------------------

[](#support-this-project)

As you may know, OpenAI PHP is an open-source project wrapping tool for OpenAI. We rely on the support of our community to continue developing and maintaining the project, and one way that you can help is by making a donation.

Donations allow us to cover expenses such as hosting costs(for testing), development tools, and other resources that are necessary to keep the project running smoothly. Every contribution, no matter how small, helps us to continue improving OpenAI PHP for everyone.

If you have benefited from using OpenAI PHP and would like to support its continued development, we would greatly appreciate a donation of any amount. You can make a donation through;

- [Buy me a coffee](https://www.buymeacoffee.com/orhane)
- [Patreon](https://patreon.com/orhann)
- [Click here for the Coinbase QR](#btc) **Bitcoin** &gt; 34w2DftWGkDqDbYMixkmdWWMLmaP9uTRz7
- [Click here for the Coinbase QR](#doge) **Dogecoin** &gt; DHiqcZox9M8kYDn7BkesnN6Z2kJ7dYG9Lc
- [Click here for the Coinbase QR](#eth) **Ethereum** &gt; 0x135E2D5d7AC40c6850f844BA589D68e91a268Ceb

Thank you for considering a donation to lyhiving/OpenAI PHP SDK. Your support is greatly appreciated and helps to ensure that the project can continue to grow and improve.

*Sincerely,*

**Orhan Erday** / Creator.

Endpoint Support
================

[](#endpoint-support)

- Chat
    - [ChatGPT API](#chat-as-known-as-chatgpt-api)
- Models
    - [List models](https://beta.openai.com/docs/api-reference/models/list)
    - [Retrieve model](https://beta.openai.com/docs/api-reference/models/retrieve)
- Completions
    - [Create completion](https://beta.openai.com/docs/api-reference/completions/create)
- Edits
    - [Create edits](https://beta.openai.com/docs/api-reference/edits/create)
- Images
    - [Create image](https://beta.openai.com/docs/api-reference/images/create)
    - [Create image edit](https://beta.openai.com/docs/api-reference/images/create-edit)
    - [Create image variation](https://beta.openai.com/docs/api-reference/images/create-variation)
- Embeddings
    - [Create embeddings](https://beta.openai.com/docs/api-reference/embeddings/create)
- Audio
    - [Create transcription](https://platform.openai.com/docs/api-reference/audio/create)
    - [Create translation](https://platform.openai.com/docs/api-reference/audio/create)
- Files
    - [List files](https://beta.openai.com/docs/api-reference/files/list)
    - [Upload file](https://beta.openai.com/docs/api-reference/files/upload)
    - [Delete file](https://beta.openai.com/docs/api-reference/files/delete)
    - [Retrieve file](https://beta.openai.com/docs/api-reference/files/retrieve)
    - [Retrieve file content](https://beta.openai.com/docs/api-reference/files/retrieve-content)
- Fine-tunes
    - [Create fine-tune (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/create)
    - [List fine-tunes (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/list)
    - [Retrieve fine-tune (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/retrieve)
    - [Cancel fine-tune (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/cancel)
    - [List fine-tune events (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/events)
    - [Delete fine-tune model (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/delete-model)
- Moderation
    - [Create moderation](https://beta.openai.com/docs/api-reference/moderations/create)
- Engines *(deprecated)*
    - [List engines](https://beta.openai.com/docs/api-reference/engines/list)
    - [Retrieve engine](https://beta.openai.com/docs/api-reference/engines/retrieve)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require lyhiving/open-ai
```

Quick Start ⚡
-------------

[](#quick-start-)

Before you get starting, you should set OPENAI\_API\_KEY as ENV key, and set OpenAI key as env value with the following commands;

*Powershell*

```
$Env:OPENAI_API_KEY = "sk-gjtv....."
```

*Cmd*

```
set OPENAI_API_KEY=sk-gjtv.....
```

*Linux or macOS*

```
export OPENAI_API_KEY=sk-gjtv.....
```

> Getting issues while setting up env? Please read the [article](https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety) or you can check my [StackOverflow answer](https://stackoverflow.com/a/73904271/15196622) for the Windows® ENV setup.

Create your `index.php` file and paste the following code part into the file.

```
