PHP code example of goed / cerebras-php

1. Go to this page and download the library: Download goed/cerebras-php 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/ */

    

goed / cerebras-php example snippets



Goed\Cerebras\Client;

$client = new Client();
$response = $client->chat()->create([
    'model' => 'llama3.1-8b',
    'messages' => [
        ['role' => 'user', 'content' => 'Hello, how are you?']
    ]
]);

echo $response['choices'][0]['message']['content'];


Goed\Cerebras\Client;

$client = new Client();
$stream = $client->chat()->create([
    'model' => 'llama3.1-8b',
    'messages' => [
        ['role' => 'user', 'content' => 'Tell me a story.']
    ],
    'stream' => true
]);

foreach ($stream as $chunk) {
    echo $chunk['choices'][0]['delta']['content'] ?? '';
}
bash
composer 
bash
export CEREBRAS_API_KEY=your_api_key_here