Download the PHP package aisdk/xai without Composer

On this page you can find all versions of the php package aisdk/xai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package xai

aisdk/xai

GitHub Workflow Status Total Downloads Latest Version License Why PHP in 2026


Official xAI provider for the PHP AI SDK. Uses shared OpenAI-compatible wire adapters for text generation.

Installation

Live sessions need a transport. Install the ready-made implementation, or use any application transport that implements the contracts from aisdk/core:

Basic Usage

Model IDs pass through unchanged and do not need to be registered. This package does not ship a model inventory; the SDK performs internal adapter validation before xAI validates support for the selected model.

Configuration

Variable Description Default
XAI_API_KEY API key for authentication Required
XAI_BASE_URL Base URL for API requests https://api.x.ai/v1

Supported Capabilities

Capability Support
Text generation and streaming Native
Tool calling Native
Reasoning Native
Image generation Native
Speech generation Native
Transcription Native
Embeddings Native
Video generation Native
Live voice WebSocket and SIP control
Live transcription Dedicated binary-audio WebSocket
Live translation Not provided by xAI
WebRTC signalling Not provided by xAI

Image Generation

Speech Generation

Transcription

The xAI STT endpoint does not accept a model field, so the selected ID remains an opaque SDK model reference while the provider adapter calls the dedicated service. Local audio and HTTP URLs are supported.

Live Voice Agents

AiSdk\Live is part of core. aisdk/xai owns the xAI Voice Agent endpoint, authentication, session protocol, tool loop, normalized events, ephemeral credentials, and SIP control. aisdk/transport only supplies the WebSocket.

The example treats STDIN and STDOUT as raw 24 kHz mono PCM16. In an application, the same calls can be connected to microphone and speaker I/O.

To resume an opted-in xAI conversation, put its server-issued ID in the provider connection query while keeping resumption enabled in the session:

Without aisdk/transport, inject your own core transport:

The core repository includes a complete AppWebSocketTransport using amphp/websocket-client. The application transport only moves frames; xAI event names and message schemas remain encapsulated by this package.

Voice tools

Registered core tools with handlers run automatically. Unknown or handler-less calls are emitted for manual handling:

xAI parallel function calls are coordinated as one turn: every output is sent before exactly one continuation request.

Live Transcription

xAI's dedicated streaming STT protocol sends raw audio as binary WebSocket frames. Partial transcripts are cumulative and can revise earlier text, so the portable event is TranscriptUpdate, not append-only TranscriptDelta.

Client Secrets

Issue short-lived xAI Voice Agent credentials from a trusted server:

The browser authenticates its native WebSocket with the documented subprotocol prefix:

xAI's credential endpoint accepts expiry configuration only. Voice, instructions, and tools are configured after the client opens its Live session; this package intentionally does not send them in the credential request.

SIP Calls and Server Controls

Verify the exact raw xAI webhook body, attach a WebSocket to its call_id, and hang up when complete. xAI makes an incoming SIP call available immediately and does not document a separate accept endpoint, so the shared accept() method is intentionally a no-op for this provider.

Webhook verification enforces the signed raw bytes and the five-minute timestamp window. Do not parse and re-encode the body first.

Video Generation

Image-to-video, editing, extension, and reference-to-video are available through normalized image/video inputs and providerOptions('xai', ...).

Reasoning

Provider-Specific Options

Testing

The default suite uses protocol fixtures and conformance checks. Credentialed Live network verification is separate from the default test run.

Documentation

Community


All versions of xai with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
aisdk/core Version ^0.8.0
aisdk/openai-compatible Version ^0.8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package aisdk/xai contains the following files

Loading the files please wait ...