PHP code example of ay4t / php-rest-client

1. Go to this page and download the library: Download ay4t/php-rest-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ay4t / php-rest-client example snippets



$config = new Config();
$config->setBaseUri('https://api.groq.com/openai/v1')
    ->setApiKey('your-api-key-here')
    // optional
    ->setSecretKey('your-secret-key-here');

$client = new Client($config);
$response = $client->cmd('GET', 'models');

echo '<pre>';
print_r($response);
echo '</pre>';

$cmd = $client->cmd('POST', 'chat/completions', [
    'model' => 'llama-3.1-70b-versatile',
    'messages' => [
        [
            'role' => 'user',
            'content'  => 'hi, why is sea water salty?',
        ]
    ]
]);

echo '<pre>';
print_r($cmd);
echo '</pre>';