tibor-src / xai-sdk-laravel
Unofficial Laravel integration for tibor-src/xai-sdk-php.
Requires
- php: ^8.2.0
- illuminate/support: ^11.48.0 || ^12.56.0 || ^13.23.0
- tibor-src/xai-sdk-php: ^0.2.1
Requires (Dev)
- larastan/larastan: ^3.10.0
- laravel/pint: ^1.30.3
- orchestra/testbench: ^9.12.0 || ^10.8.0 || ^11.3.0
- pestphp/pest: ^3.8.5 || ^4.7.5
- pestphp/pest-plugin-type-coverage: ^3.0 || ^4.0
Suggests
None
Provides
None
Conflicts
- laravel/framework: <11.48.0 || >=14.0.0
Replaces
None
README
Unofficial Laravel package for tibor-src/xai-sdk-php.
This package is not published or maintained by xAI. It registers that PHP client's SpaceXAI class in the Laravel container. Request and response behavior comes from tibor-src/xai-sdk-php.
Install
composer require tibor-src/xai-sdk-laravel
Requires PHP 8.2 or newer. Set XAI_API_KEY in the environment, then publish the config if you want to override the client's constructor options:
php artisan vendor:publish --tag=xai-config
The published config/xai.php reads XAI_API_KEY. Leave the other values null to keep the PHP client's defaults.
Usage
use TiborSrc\XaiSdkPhp\SpaceXAI; $client = app(SpaceXAI::class); $response = $client->responses->create([ 'model' => 'grok-4.7', 'input' => 'Explain why the sky is blue in one sentence.', ]); echo $response->toText();
The client sends store as false unless you opt in. That differs from the API wire default. With storage disabled, it requests encrypted reasoning content so $response->toInput() can preserve context between turns. A create call that omits stream is sent as a stream and returned as the finished response. Pass 'stream' => false for one JSON response, or 'stream' => true for a ResponseStream.
TiborSrc\XaiSdkLaravel\Facades\SpaceXAI resolves the same container binding. Resources are public properties on the client, so call them on the resolved instance: SpaceXAI::getFacadeRoot()->responses->create(...).
Resources
The binding is the PHP client. It exposes:
responses(create,compact,get,delete,inputItems->list)models(list,get, pluslanguage,image, andvideo)images(generate,edit)videos(generate,edit,extend,get,wait)files(upload,list,get,delete,content,createPublicUrl,revokePublicUrl)batches(create,list,get,cancel,results,wait,requests)voice(speak,transcribe,list,get,custom,clientSecrets)tokenizer(encode)account(apiKey)
Tests
composer test
That runs Pint, PHPStan at the maximum level, Pest's type coverage at 100%, and the test suite. Tests mock the PHP client's HTTP layer and do not call the live API.
License
Apache License 2.0. See LICENSE and NOTICE.