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.
XAITextModel lives in the AiSdk\XAI\Models namespace and is the concrete text model implementation for xAI’s Grok family. It extends BaseModel and implements TextModelInterface, delegating HTTP work to the shared aisdk/openai-compatible helpers — ChatRequestBuilder serialises the outgoing request, ChatResponseParser deserialises blocking responses, and ChatStreamParser drives token-by-token streaming. The model catalog (resources/models.json) supplies capability data for every known Grok variant; unknown model IDs fall back gracefully rather than hard-failing.
Namespace
XAITextModel is typically obtained via XAI::model() rather than
constructed directly. See the XAI facade reference
for setup instructions.Constructor
| Parameter | Type | Description |
|---|---|---|
$modelId | string | The Grok model identifier, e.g. 'grok-4' or 'grok-3-mini'. |
$options | XAIOptions | Provider configuration: base URL, API key, and SDK HTTP dependencies. |
$registry | ModelRegistry|null | Optional runtime registry for custom capability overrides. Defaults to null. |
Methods
provider(): string
Returns the provider name used throughout the SDK for namespacing metadata and capability lookups.
modelId(): string
Returns the model identifier that was supplied at construction time.
capabilities(): array<int, Capability>
Returns the full list of Capability enum cases supported by this model. The method resolves the list in priority order:
- Model registry — if a
ModelRegistrywas injected and contains an entry for this(provider, modelId)pair, that definition’s capability list is used. - Catalog — otherwise the bundled
resources/models.jsoncatalog is consulted.
TextGeneration, Streaming, ToolCalling, StructuredOutput, Reasoning, TextInput, ImageInput.
capability(Capability $capability): CapabilitySupport
Resolves the support status for a single capability, walking the following chain until a definitive answer is found:
- Configured overrides — capability flags set on the
XAIOptionsinstance. - Model registry — result from the injected
ModelRegistry, if present. - Catalog — bundled
resources/models.json. - Unknown-model fallback — if the model ID is not present in the catalog and the queried capability is
Capability::TextGeneration, the method returnsCapabilitySupport::supported($capability, 'unknown-model-fallback')instead of reporting unsupported.
generate(TextModelRequest $request): TextModelResponse
Sends a blocking chat completion request and returns a fully-resolved TextModelResponse.
Internally:
- Serialises the request with
ChatRequestBuilder::build()withstream: false. - POSTs to
{baseUrl}/chat/completionsvia the SDK HTTP runner. - Deserialises the JSON response with
ChatResponseParser::parse().
| Parameter | Type | Description |
|---|---|---|
$request | TextModelRequest | The portable text model request object. |
TextModelResponse — contains text, usage, finishReason, and providerMetadata.
stream(TextModelRequest $request): Generator
Sends a streaming chat completion request and returns a PHP Generator that yields partial TextModelResponse chunks as they arrive from the server.
Internally:
- Serialises the request with
ChatRequestBuilder::build()withstream: true. - Opens a streaming POST to
{baseUrl}/chat/completions. - Pipes server-sent events through
ChatStreamParser::parse(), whichyields each delta chunk.
| Parameter | Type | Description |
|---|---|---|
$request | TextModelRequest | The portable text model request object. |
Generator — each iteration yields a partial TextModelResponse chunk.
Endpoint
https://api.x.ai/v1Full default endpoint:
https://api.x.ai/v1/chat/completions
The base URL can be overridden by passing a custom baseUrl in XAI::create() options.