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.
XAIProvider lives in the AiSdk\XAI namespace and is the concrete provider implementation for xAI. It extends BaseProvider and holds a single XAIOptions instance that carries the API key, base URL, headers, and optional HTTP client. You typically obtain a provider through the XAI facade, but you can also instantiate it directly when you need explicit control over configuration.
Namespace and import
Constructor
A fully constructed
XAIOptions object containing the API key, base URL, extra headers, and optional Sdk instance. Use XAIOptions::fromArray() to build one from a plain associative array.Methods
name()
Always
'xai' — the value of XAIOptions::PROVIDER_NAME.textModel()
XAITextModel for the given model ID, injecting the provider’s XAIOptions and model registry.
The identifier of the Grok language model to create. For example:
'grok-4', 'grok-3-turbo', 'grok-2-vision'.A configured
XAITextModel instance ready to generate text.imageModel()
XAIImageModel for the given model ID, injecting the provider’s XAIOptions and model registry.
The identifier of the xAI image model to create. For example:
'grok-imagine-image-quality'.A configured
XAIImageModel instance ready to generate images.Creating directly (vs. using the facade)
If you need full control over the provider lifecycle — for example, to manage multiple providers with different API keys in the same process — instantiateXAIProvider directly instead of going through the XAI facade.