This guide will help you get started with PHP using the Yescale AI with OpenAI.

1

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.

2

Install the openai-php/client library

Run the following command in your terminal to install the openai-php/client library:

3

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.

4

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:

example.php
<?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.