The xAI provider (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/xai/llms.txt
Use this file to discover all available pages before exploring further.
aisdk/xai) brings xAI’s Grok models into the PHP AI SDK ecosystem. It implements the shared OpenAI-compatible adapter so you can generate text, stream completions, produce images, and leverage Grok’s reasoning capabilities — all from a unified PHP interface.
Installation
Add the provider to your project with a single Composer command
Quickstart
Make your first Grok API call in under five minutes
Guides
Explore text generation, streaming, image generation, and reasoning
API Reference
Full class and method reference for the xAI provider
What you can do
Text Generation
Generate completions with any Grok text model using the fluent builder API
Streaming
Stream tokens in real time with PHP generators for responsive UIs
Image Generation
Create images with
grok-imagine-image-quality with aspect ratio controlReasoning
Control reasoning effort (low / medium / high) on Grok 3 and 4 models
Tool Calling
Bind PHP functions as tools for function-calling workflows
Provider Options
Pass raw xAI-specific parameters like
search_parameters directlyGet started in minutes
Set your API key
Export the
XAI_API_KEY environment variable, or pass it directly when creating the provider.Requires PHP 8.3+ and Composer. The provider depends on
aisdk/core and aisdk/openai-compatible, both installed automatically.