khaiphan / openai-auth
A PHP library for authenticating with OpenAI
dev-main
2023-06-02 05:14 UTC
Requires
- php: >=7.2
- rmccue/requests: ^2.0
This package is auto-updated.
Last update: 2024-12-30 02:44:47 UTC
README
OpenAIAuth is a Composer package that allows you to authenticate with OpenAI/ChatGPT using PHP code.
Languages
Installation
Requires a minimum PHP version of 7.2
Use Composer to install the package.
Run the following command in the terminal:
composer require khaiphan/openai-auth:dev-main
Usage
- First, include the autoloader in your PHP code:
require 'vendor/autoload.php';
- Next, create an instance of the
Auth0
class and provide your OpenAI username and password:
use KhaiPhan\OpenAi\Auth; $OpenAIAuth = new Auth('OpenAI_username', 'OpenAI_password');
- Then, call the
auth()
method to authenticate and obtain the access token:
$auth = $OpenAIAuth->auth();
- You can access the access token through the
$auth['access_token']
variable. For example:
$accessToken = $auth['access_token']; echo $accessToken;
Make sure to replace 'OpenAI_username'
and 'OpenAI_password'
with your actual authentication credentials.
License
This package is open source and available under the MIT License.