PHPackages                             aisdk/xai - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aisdk/xai

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aisdk/xai
=========

Official xAI provider for the PHP AI SDK.

v0.3.0(2d ago)012—0%MITPHP ^8.3

Since Jul 7Compare

[ Source](https://github.com/phpaisdk/xai)[ Packagist](https://packagist.org/packages/aisdk/xai)[ Docs](https://github.com/phpaisdk/xai)[ RSS](/packages/aisdk-xai/feed)WikiDiscussions Synced today

READMEChangelog (6)Dependencies (7)Versions (7)Used By (0)

aisdk/xai
=========

[](#aisdkxai)

Official xAI provider for the PHP AI SDK. Uses the shared OpenAI-compatible chat-completions adapter for v0.1 text support.

Installation
------------

[](#installation)

```
composer require aisdk/xai
```

Basic Usage
-----------

[](#basic-usage)

```
use AiSdk\Generate;
use AiSdk\XAI;

$result = Generate::text()
    ->model(XAI::model('grok-4.3'))
    ->instructions('Write short, clear answers.')
    ->prompt('Explain closures in PHP.')
    ->run();

echo $result->text;
```

Image Generation
----------------

[](#image-generation)

```
use AiSdk\Generate;
use AiSdk\XAI;

$result = Generate::image()
    ->model(XAI::image('grok-imagine-image-quality'))
    ->prompt('A clean app icon for a PHP AI SDK')
    ->aspectRatio('1:1')
    ->run();

$result->output->save(__DIR__.'/icon.png');
```

Speech Generation
-----------------

[](#speech-generation)

```
use AiSdk\Generate;
use AiSdk\XAI;

$result = Generate::speech()
    ->model(XAI::speech('grok-voice'))
    ->input('Hello from xAI voice.')
    ->voice('eve')
    ->format('mp3')
    ->providerOptions('xai', [
        'language' => 'auto',
        'speed' => 1.1,
    ])
    ->run();

$result->output->save(__DIR__.'/speech.mp3');
```

Configuration
-------------

[](#configuration)

VariableDescriptionDefault`XAI_API_KEY`API key for authenticationRequired`XAI_BASE_URL`Base URL for API requests`https://api.x.ai/v1````
XAI::create([
    'apiKey' => 'xai-...',
    'baseUrl' => 'https://api.x.ai/v1',
]);
```

Reasoning
---------

[](#reasoning)

```
use AiSdk\Reasoning;

$result = Generate::text('Explain the tradeoff.')
    ->model(XAI::model('grok-4.3'))
    ->reasoning(Reasoning::effort('low'))
    ->run();
```

Provider-Specific Options
-------------------------

[](#provider-specific-options)

```
$result = Generate::text('Hello')
    ->model(XAI::model('grok-4.3'))
    ->providerOptions('xai', [
        'raw' => ['search_parameters' => ['mode' => 'auto']],
    ])
    ->run();
```

Testing
-------

[](#testing)

```
composer test
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance99

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

2d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef29d1962da41e7526023f215cf844494e209b2fd163742084cb919a3b508021?d=identicon)[aisdk](/maintainers/aisdk)

---

Tags

aillmgrokx.aiopenai-compatibleaisdk

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aisdk-xai/health.svg)

```
[![Health](https://phpackages.com/badges/aisdk-xai/health.svg)](https://phpackages.com/packages/aisdk-xai)
```

###  Alternatives

[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

318123.0k1](/packages/cognesy-instructor-php)[ardagnsrn/ollama-php

This is a PHP library for Ollama. Ollama is an open-source project that serves as a powerful and user-friendly platform for running LLMs on your local machine. It acts as a bridge between the complexities of LLM technology and the desire for an accessible and customizable AI experience.

21284.7k](/packages/ardagnsrn-ollama-php)[symfony/ai-agent

PHP library for building agentic applications.

32870.1k107](/packages/symfony-ai-agent)[soukicz/llm

LLM client with support for cache, tools and async requests

4414.3k](/packages/soukicz-llm)[anilcancakir/laravel-ai-sdk-skills

A skill system for Laravel AI SDK agents. Define reusable AI capabilities with SKILL.md files.

2212.1k](/packages/anilcancakir-laravel-ai-sdk-skills)[wordpress/ai-provider-for-anthropic

AI Provider for Anthropic for the PHP AI Client SDK. Works as both a Composer package and WordPress plugin.

191.0k](/packages/wordpress-ai-provider-for-anthropic)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
