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.
Package xai
Short Description Official xAI provider for the PHP AI SDK.
License MIT
Homepage https://github.com/phpaisdk/xai
Informations about the package xai
aisdk/xai
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
- Contributing
- Support
- For private security reports, email [email protected].