TheDocumentation 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.
XAI class in namespace AiSdk is the main entry point for the xAI PHP provider. It acts as a static facade over an XAIProvider singleton, so you can call XAI::model() or XAI::image() anywhere in your application without manually constructing or passing a provider instance. Internally it uses the RegistersModels trait and holds a single default XAIProvider that is lazily created the first time it is needed.
Namespace and import
Methods
XAI::create()
XAIProvider from the given configuration array and stores it as the default singleton, replacing any previously set default.
Associative configuration array passed directly to
XAIOptions::fromArray(). Accepted keys are apiKey, baseUrl, headers, and sdk. When a key is omitted the corresponding environment variable (XAI_API_KEY, XAI_BASE_URL) is read automatically.The newly created (and stored)
XAIProvider instance.XAI::default()
XAIProvider singleton. If no provider has been created yet, it lazily calls create() with an empty config array, which loads credentials from the XAI_API_KEY environment variable.
The current default
XAIProvider instance, auto-created if necessary.XAI::model()
TextModelInterface for the given Grok model ID by delegating to the default provider’s textModel() method.
The identifier of the Grok language model to use. For example:
'grok-4', 'grok-3-turbo', 'grok-2-vision'.A ready-to-use text model instance bound to the requested model ID.
XAI::image()
ImageModelInterface for the given image model ID by delegating to the default provider’s imageModel() method.
The identifier of the xAI image model to use. For example:
'grok-imagine-image-quality'.A ready-to-use image model instance bound to the requested model ID.
XAI::reset()
null. Use this in test teardown hooks to prevent state from leaking between test cases.