Skip to main content

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

use AiSdk\XAI\XAIProvider;
use AiSdk\XAI\XAIOptions;

Constructor

public function __construct(public readonly XAIOptions $options)
options
XAIOptions
required
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()

public function name(): string
Returns the canonical provider identifier string.
return
string
Always 'xai' — the value of XAIOptions::PROVIDER_NAME.

textModel()

public function textModel(string $modelId): TextModelInterface
Instantiates an XAITextModel for the given model ID, injecting the provider’s XAIOptions and model registry.
modelId
string
required
The identifier of the Grok language model to create. For example: 'grok-4', 'grok-3-turbo', 'grok-2-vision'.
return
TextModelInterface
A configured XAITextModel instance ready to generate text.

imageModel()

public function imageModel(string $modelId): ImageModelInterface
Instantiates an XAIImageModel for the given model ID, injecting the provider’s XAIOptions and model registry.
modelId
string
required
The identifier of the xAI image model to create. For example: 'grok-imagine-image-quality'.
return
ImageModelInterface
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 — instantiate XAIProvider directly instead of going through the XAI facade.
use AiSdk\XAI\XAIOptions;
use AiSdk\XAI\XAIProvider;

$provider = new XAIProvider(
    XAIOptions::fromArray(['apiKey' => 'xai-...'])
);

$model = $provider->textModel('grok-4');

Build docs developers (and LLMs) love