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.
XAIImageModel lives in the AiSdk\XAI\Models namespace and is the concrete image model implementation for xAI’s Grok image generation API. It extends BaseModel and implements ImageModelInterface, using the shared aisdk/openai-compatible helpers — ImageRequestBuilder constructs the outgoing payload and ImageResponseParser decodes the response. Because xAI’s image endpoint uses an aspect_ratio field rather than a pixel size string, the model is pre-configured with xAI-specific builder options that suppress the size and seed parameters automatically.
Namespace
XAIImageModel is typically obtained via XAI::image() rather than
constructed directly. See the XAI facade reference
for setup instructions.Constructor
| Parameter | Type | Description |
|---|---|---|
$modelId | string | The image model identifier, e.g. 'grok-imagine-image-quality'. |
$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.
grok-imagine-image-quality catalog entry declares three capabilities: ImageGeneration, TextInput, and 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.
generate(ImageRequest $request): ImageResponse
Sends an image generation request and returns a fully-resolved ImageResponse.
Internally:
-
Serialises the request with
ImageRequestBuilder::build()using the following xAI-specific options:Option Value Effect aspectRatioParameter'aspect_ratio'Sends aspect ratio as aspect_ratioin the request body.inferSizeFromAspectRatiofalseDisables automatic size inference from aspect ratio. sizeParameternullThe sizefield is never included in the request.seedParameternullThe seedfield is never included in the request. -
POSTs to
{baseUrl}/images/generationsvia the SDK HTTP runner. -
Deserialises the JSON response with
ImageResponseParser::parse().
resolution) via providerOptions():
| Parameter | Type | Description |
|---|---|---|
$request | ImageRequest | The portable image model request object. |
ImageResponse — contains output (with base64 and a save() helper), usage, and providerMetadata.
Endpoint
https://api.x.ai/v1Full default endpoint:
https://api.x.ai/v1/images/generations
The base URL can be overridden by passing a custom baseUrl in XAI::create() options.
Response format
All image responses are returned asb64_json — the response body carries base-encoded image data, accessible via $result->output->base64. The size parameter is never sent to the xAI API; use ->aspectRatio() on the Generate::image() builder to control image dimensions instead.