Search by

tibor-src / xai-sdk-laravel

tibor-src

This package is abandoned and no longer maintained. The author suggests using the tibor-src/grok-sdk-laravel package instead.

Unofficial Laravel integration for tibor-src/xai-sdk-php.

Package info

github.com/tibor-src/xai-sdk-laravel

pkg:composer/tibor-src/xai-sdk-laravel

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.2.13 2026-12-02 02:30 UTC

README

Succeeded by tibor-src/grok-sdk-laravel. Install with composer require tibor-src/grok-sdk-laravel. Packagist: tibor-src/grok-sdk-laravel. Mapping: UPGRADE.md.

Unofficial Laravel package for tibor-src/xai-sdk-php.

This package is not published or maintained by xAI. It registers that PHP client's Grok class in the Laravel container. SpaceXSI is an alias of the same binding. SpaceXAI remains a deprecated alias. 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 and tibor-src/xai-sdk-php 0.2.13 or newer. Set XAI_API_KEY or GROK_API_KEY in the environment (XAI_API_KEY is used when both are set), 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, then GROK_API_KEY if XAI_API_KEY is unset or empty. Leave the other values null to keep the PHP client's defaults. When api_key is empty, the PHP client still reads those two variables itself, with the same order.

Usage

use TiborSrc\XaiSdkPhp\Grok;

$client = app(Grok::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\Grok and TiborSrc\XaiSdkLaravel\Facades\SpaceXSI resolve the same container binding. TiborSrc\XaiSdkLaravel\Facades\SpaceXAI still resolves that binding and is deprecated. Resources are public properties on the client, so call them on the resolved instance: Grok::getFacadeRoot()->responses->create(...).

config/xai.php passes timeout and idle_timeout through to the PHP client. Null keeps the client's default. 0, a negative value, or anything longer than 24 hours becomes 24 hours. The same 24-hour cap applies to videos->wait() and batches->wait(): a timeout or interval longer than 24 hours means 24 hours. A wait() timeout of 0 or less still expires at once, and an interval of 0 or less still polls again without a pause.

retry_before_output still defaults to off. When it is true, the PHP client retries a dropped connection before the first response byte. That includes a streamed responses->create() whose connection drops after the 200 headers and before the first byte of the event stream.

Resources

The binding is the PHP client. It exposes:

  • responses (create, compact, get, delete, inputItems->list)
  • models (list, get, plus language, image, and video)
  • 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)

xai-sdk-php 0.2.13

The resolved client uses tibor-src/xai-sdk-php 0.2.13 (@grok/sdk 0.2.13, also published as @xai-official/sdk). This package requires ^0.2.13.

  • README examples now use the Grok client. SpaceXSI and the deprecated SpaceXAI remain aliases of the same class and the same container binding. TiborSrc\XaiSdkLaravel\Facades\Grok is not deprecated.
  • A request sends user-agent: xai-sdk/0.2.13 (php) unless default_headers already sets user-agent.
  • xai-sdk-version is php/0.2.13 on every request. A value set in default_headers is replaced with that.
use TiborSrc\XaiSdkLaravel\Facades\Grok;
use TiborSrc\XaiSdkPhp\Grok as GrokClient;

$client = app(GrokClient::class);

echo Grok::getFacadeRoot() === $client ? 'same client' : 'different';

xai-sdk-php 0.2.12

The resolved client uses tibor-src/xai-sdk-php 0.2.12 (@xai-official/sdk 0.2.12). This package required ^0.2.12.

  • TiborSrc\XaiSdkPhp\Grok is an alias of SpaceXSI. The container binds one client under SpaceXSI, Grok, and the deprecated SpaceXAI keys. TiborSrc\XaiSdkLaravel\Facades\Grok resolves that same instance. Grok is not deprecated.
  • config/xai.php reads XAI_API_KEY, then GROK_API_KEY if XAI_API_KEY is unset or empty. When api_key is empty, the PHP client reads those two variables in the same order. XAI_API_KEY is used when both are set. A non-empty api_key still overrides both. The missing-key error names both variables.
  • A request sends user-agent: xai-sdk/0.2.12 (php) unless default_headers already sets user-agent.
  • xai-sdk-version is php/0.2.12 on every request. A value set in default_headers is replaced with that.
use TiborSrc\XaiSdkLaravel\Facades\Grok;
use TiborSrc\XaiSdkPhp\Grok as GrokClient;

$client = app(GrokClient::class);

echo Grok::getFacadeRoot() === $client ? 'same client' : 'different';

xai-sdk-php 0.2.11.1

The resolved client uses tibor-src/xai-sdk-php 0.2.11.1, the installable 0.2.11 port (@xai-official/sdk 0.2.11). Packagist locked published 0.2.11 to an earlier commit, so this package requires ^0.2.11.1. Config, the facades, and the service provider are unchanged.

  • A request sends user-agent: xai-sdk/0.2.11.1 (php) unless default_headers already sets user-agent.
  • xai-sdk-version is php/0.2.11.1 on every request. A value set in default_headers is replaced with that.
  • voice->transcribe() takes redact and show_redacted_text. redact is a list of groups (pii, pci, phi) or single types such as ssn, each sent as its own redact field. With show_redacted_text set to true, each redacted word has the original words in redacted_text. TiborSrc\XaiSdkPhp\KNOWN_TRANSCRIPTION_REDACTIONS lists the groups this release names; any other string is still sent.
  • TiborSrc\XaiSdkPhp\KNOWN_MODEL_IDS no longer lists grok-build-0.1. It reached end of life on November 19, 2026. responses->create() still sends whatever model id you pass. The API no longer serves this model.
  • Resource methods that take an id throw a TypeError for an empty id, ".", or ".." instead of sending the request.
  • responses->create() without stream, and $stream->done(), keep the completed response when the connection fails after the terminal event. Later events are not delivered.
use TiborSrc\XaiSdkPhp\Http\Blob;
use TiborSrc\XaiSdkPhp\SpaceXSI;

$redacted = app(SpaceXSI::class)->voice->transcribe([
    'file' => new Blob(file_get_contents('./call.mp3'), 'audio/mpeg'),
    'language' => 'en',
    'redact' => ['pii', 'pci'],
    'show_redacted_text' => true,
]);

echo $redacted->text;

xai-sdk-php 0.2.10

The resolved client uses tibor-src/xai-sdk-php 0.2.10. Config, the facades, and the service provider are unchanged.

  • A request sends user-agent: xai-sdk/0.2.10 (php) unless default_headers already sets user-agent.
  • xai-sdk-version is php/0.2.10 on every request. A value set in default_headers is replaced with that.

xai-sdk-php 0.2.9

The resolved client uses tibor-src/xai-sdk-php 0.2.9. Config, the facades, and the service provider are unchanged.

  • Streamed responses keep one event's event: and data: lines together when the server ends lines with \r\n, including when a chunk splits that line break. \r followed by \r\n, and \n followed by \r\n, still end an event. Bare \r and \n line endings are unchanged.
  • TiborSrc\XaiSdkPhp\KNOWN_IMAGE_MODEL_IDS lists grok-imagine-image and grok-imagine-image-2.0. grok-imagine-image-quality was retired on November 2, 2026. images->generate() still sends whatever model id you pass. Use grok-imagine-image-2.0 for new work.
use TiborSrc\XaiSdkPhp\SpaceXSI;

$image = app(SpaceXSI::class)->images->generate([
    'model' => 'grok-imagine-image-2.0',
    'prompt' => 'A red cube on a white table',
]);

xai-sdk-php 0.2.8

The resolved client forwards request bodies to tibor-src/xai-sdk-php 0.2.8. This package does not validate aspect ratios, guidelines, model ids, or transcription formats.

  • responses->create() accepts guidelines. Each entry is ['type' => 'policy', 'category' => ..., 'behavior' => ...]. category is nsfw, violence, profanity, or cyber. behavior is decline for nsfw, violence, and profanity, and allow for cyber only. The API rejects other pairs with 400, and it rejects the old sexual, self_harm, illicit, and offer_support values with 422. cyber must be enabled for the API key. Each category may appear at most once.
  • $response->watermarked and $stream->watermarked are true when the response has the header x-watermark: true. Watermarking is on by default for supported models from November 7, 2026.
  • incomplete_details.reason can be content_filter. temperature and top_p are sent as given. The API samples temperature above 1 at 1, and top_p above the model's default at that default.
  • voice->transcribe() accepts audio_format webm, avi, and mov. A Blob without a name is sent as audio.webm, audio.avi, or audio.mov when its MIME type or first bytes say so.
  • videos->generate() accepts aspect_ratio 21:9 and 5:2, along with 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, and 2:3.
  • voice->clientSecrets->create() accepts the realtime models in TiborSrc\XaiSdkPhp\KNOWN_REALTIME_MODEL_IDS: grok-voice-latest (which points to grok-voice-3.0), grok-voice-3.0, grok-voice-2.0, and grok-voice-think-fast-2.0. A session that asks for grok-voice-think-fast-2.0 reports grok-voice-2.0.
  • Live search is removed. The API returns HTTP 410 for search_parameters and rejects a tool with type live_search. Use webSearch() and xSearch(). web_search_options is the chat-completions form of that removal; this client has no chat-completions resource.
  • A request may include up to 1000 tools. xSearch() allowed_x_handles and excluded_x_handles each take up to 20 handles. The client does not enforce either limit.
use TiborSrc\XaiSdkPhp\SpaceXSI;

use function TiborSrc\XaiSdkPhp\webSearch;
use function TiborSrc\XaiSdkPhp\xSearch;

$response = app(SpaceXSI::class)->responses->create([
    'model' => 'grok-4.7',
    'input' => 'Hello',
    'guidelines' => [
        ['type' => 'policy', 'category' => 'violence', 'behavior' => 'decline'],
        ['type' => 'policy', 'category' => 'cyber', 'behavior' => 'allow'],
    ],
    'tools' => [webSearch(), xSearch()],
]);

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.