PHP
Get started with PHP using the Yescale AI with OpenAI
This guide will help you get started with PHP using the Yescale AI with OpenAI.
Ensure your PHP version is 8.1+
Make sure you are using PHP version 8.1 or higher. You can check your PHP version by running the following command in your terminal:
php -v
If you need to upgrade your PHP version, follow the instructions specific to your operating system.
Install the openai-php/client library
Run the following command in your terminal to install the openai-php/client
library:
Create an account on Yescale
Go to Yescale and create an account. You will get an API key that you can use to access the Yescale API.
Change the endpoint and use your API key
Change the endpoint to Yescale’s endpoint and use your API key to authenticate your requests. For example:
<?php
require 'vendor/autoload.php';
use OpenAI\Client;
$client = new Client([
'api_key' => 'YOUR_API_KEY',
'base_uri' => 'https://yescale.one/v1',
]);
$response = $client->chatCompletions()->create([
'model' => 'gpt-4o',
'messages' => [
[
'role' => 'system',
'content' => 'Hello, how can I help you today?',
],
[
'role' => 'user',
'content' => 'I need help with my account.',
],
],
]);
print_r($response);
?>
This ensures that the script is set up to run on PHP 8.1+ and uses the openai-php/client
library to interact with the Yescale API. Make sure to replace "YOUR_API_KEY"
with your actual API key from Yescale and adjust the endpoint to match Yescale’s endpoint.