1. Go to this page and download the library: Download grok-php/laravel 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/ */
grok-php / laravel example snippets
use GrokPHP\Laravel\Facades\GrokAI;
use GrokPHP\Client\Config\ChatOptions;
use GrokPHP\Client\Enums\Model;
$response = GrokAI::chat(
[['role' => 'user', 'content' => 'Hello Grok!']],
new ChatOptions(model: Model::GROK_2)
);
echo $response['choices'][0]['message']['content'];