Larafast provides a simple way to integrate xAI API with Laravel.

Installation

  1. Create an account on xAI
  2. Create your API key from the dashboard from API Keys
  3. Add your API key to your .env file as XAI_KEY=your-api-key

That’s it, your project is ready to use xAI API.

Usage

To use xAI service, you can create an instance of XAIService and use the following methods to interact with xAI API.

For text completion

use App\Services\XAIService;

Route::get('/xai', function (XAIService $xai) {
    return $xai->completion('Hello, how are you?');
});

or

```php
$xai = app(XAIService::class);
$xai->completion('Hello, how are you?');