PHPackages                             displace/xai-sdk-php - 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. [API Development](/categories/api)
4. /
5. displace/xai-sdk-php

ActiveLibrary[API Development](/categories/api)

displace/xai-sdk-php
====================

An unofficial PHP SDK for xAI's APIs - full parity with the Python SDK

v1.2.2(4mo ago)15[1 PRs](https://github.com/DisplaceTech/xai-sdk-php/pulls)Apache-2.0PHPPHP ^8.4CI passing

Since Jan 8Pushed 1mo agoCompare

[ Source](https://github.com/DisplaceTech/xai-sdk-php)[ Packagist](https://packagist.org/packages/displace/xai-sdk-php)[ Docs](https://github.com/DisplaceTech/xai-sdk-php)[ RSS](/packages/displace-xai-sdk-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (17)Versions (7)Used By (0)

 [![xAI Logo](https://avatars.githubusercontent.com/u/130314967?s=200&v=4)](https://avatars.githubusercontent.com/u/130314967?s=200&v=4)xAI PHP SDK
===========

[](#xai-php-sdk)

An unofficial PHP SDK for xAI's APIs

 [ ![Packagist Version](https://camo.githubusercontent.com/bf0909139ed49c4ddadfcc0beca208350bfd8839f865973f6301fe350a9cce4f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646973706c6163652f7861692d73646b2d706870) ](https://packagist.org/packages/displace/xai-sdk-php) [ ![License](https://camo.githubusercontent.com/cd9662880f0fcd80a726931d428257f885736d8158c215bda0677a223a525957/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f446973706c616365546563682f7861692d73646b2d706870) ](https://github.com/DisplaceTech/xai-sdk-php/blob/main/LICENSE) [ ![PHP Version](https://camo.githubusercontent.com/eb6c57a0ef96b2a5a90aba5ae0b7c5414fe26795d8978c58299a00305a9c5b8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646973706c6163652f7861692d73646b2d706870) ](https://packagist.org/packages/displace/xai-sdk-php)

The xAI PHP SDK is a modern PHP library for interacting with xAI's APIs. Built for PHP 8.4 and above, it provides full parity with the official Python SDK, offering an intuitive and developer-friendly interface.

Whether you're generating text, images, or structured outputs, the xAI PHP SDK is designed to be robust, type-safe, and production-ready.

Documentation
-------------

[](#documentation)

Comprehensive API documentation is available at [docs.x.ai](https://docs.x.ai). Explore detailed guides, API references, and tutorials to get the most out of the xAI SDK.

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

[](#installation)

Install via Composer:

```
composer require displace/xai-sdk-php
```

### Requirements

[](#requirements)

- PHP 8.4 or higher
- `ext-json` extension
- `ext-mbstring` extension

Quick Start
-----------

[](#quick-start)

### Client Instantiation

[](#client-instantiation)

The SDK looks for the `XAI_API_KEY` environment variable by default:

```
