Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
O

open-ai

> 后端框架
Open source

OpenAI PHP SDK : Most downloaded, forked, contributed, huge community supported, and used PHP (Laravel , Symfony, Yii, Cake PHP or any PHP framework) SDK for Op

2.4K stars0 likes2 views
WebsiteGitHub

About

OpenAI PHP SDK : Most downloaded, forked, contributed, huge community supported, and used PHP (Laravel , Symfony, Yii, Cake PHP or any PHP framework) SDK for Op

OpenAI API Client in PHP



If you want to ensure this project stays alive and continues to faster improve, please please consider supporting it. Your help means a lot. Thank you!

  • Buy me a coffee
  • Patreon

ChatGPT API is currently supported, click here for the implementation introductions.


A message from creator,
Thank you for visiting the @orhanerday/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







Featured in

Comparison With Other Packages

Project Name Required PHP Version (Lower is better) Description Type (Official / Community) Support
orhanerday/open-ai PHP 7.4+ Most downloaded, forked, contributed, huge community supported, and used PHP SDK for OpenAI GPT-3 and DALL-E. It also supports chatGPT-like streaming. Community Available, (Community driven Discord Server or personal mail [email protected])
openai-** /c***t PHP 8.1+ OpenAI PHP API client. Community -

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.

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 and examples. Also you can get help from our discord channel that called #api-support

News

  • orhanerday/open-ai added to community libraries php section.
  • orhanerday/open-ai featured on PHPStorm blog post, thanks JetBrains!

Requires PHP 7.4+

Join our discord server

Click here to join the Discord server

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
  • Patreon

Thank you for considering a donation to Orhanerday/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.

Documentation

Please visit https://orhanerday.gitbook.io/openai-php-api-1/

Endpoint Support

  • Chat
    • ChatGPT API
  • Models
    • List models
    • Retrieve model
  • Completions
    • Create completion
  • Edits
    • Create edits
  • Images
    • Create image
    • Create image edit
    • Create image variation
  • Embeddings
    • Create embeddings
  • Audio
    • Text to Speech (TTS)
    • Create transcription
    • Create translation
  • Files
    • List files
    • Upload file
    • Delete file
    • Retrieve file
    • Retrieve file content
  • Fine-tunes
    • Create fine-tune (beta)
    • List fine-tunes (beta)
    • Retrieve fine-tune (beta)
    • Cancel fine-tune (beta)
    • List fine-tune events (beta)
    • Delete fine-tune model (beta)
  • Moderation
    • Create moderation
  • Engines (deprecated)
    • List engines
    • Retrieve engine
  • Assistants (beta)
    • Create assistant
    • Retrieve assistant
    • Modify assistant
    • Delete assistant
    • Lists assistants
    • Create assistant file
    • Retrieve assistant file
    • Delete assistant file
    • List assistant files
  • Threads (beta)
    • Create thread
    • Retrieve thread
    • Modify thread
    • Delete thread
  • Messages (beta)
    • Create message
    • Retrieve message
    • Modify message
    • Lists messages
    • Retrieve message file
    • List message files
  • Runs (beta)
    • Create run
    • Retrieve run
    • Modify run
    • Lists runs
    • Submit tool outputs
    • Cancel run
    • Create thread and run
    • Retrieve run step
    • List run steps

Installation

You can install the package via composer:

bash
composer require orhanerday/open-ai

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

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

Cmd

cmd
set OPENAI_API_KEY=sk-gjtv.....

Linux or macOS

bash
export OPENAI_API_KEY=sk-gjtv.....

Getting issues while setting up env? Please read the article or you can check my StackOverflow answer for the Windows® ENV setup.

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

…

Run the server with the following command

bash
php -S localhost:8000 -t .

NVIDIA NIM INTEGRATION

orhanerday/open-ai supports Nvidia NIM. The below example is MixtralAI. Check https://build.nvidia.com/explore/discover for more examples.

…

Usage

Load your key from an environment variable.

According to the following code $open_ai is the base variable for all open-ai operations.

php
use Orhanerday\OpenAi\OpenAi;

$open_ai = new OpenAi(env('OPEN_AI_API_KEY'));

Requesting organization

For users who belong to multiple organizations, you can pass a header to specify which organization is used for an API request. Usage from these API requests will count against the specified organization's subscription quota.

php
$open_ai_key = getenv('OPENAI_API_KEY');
$open_ai = new OpenAi($open_ai_key);
$open_ai->setORG("org-IKN2E1nI3kFYU8ywaqgFRKqi");

Base URL

You can specify Origin URL with setBaseURL() method;

php

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPcakephpdall-edalle2gpt-3

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架