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.

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

use AiSdk\XAI\Models\XAIImageModel;
XAIImageModel is typically obtained via XAI::image() rather than constructed directly. See the XAI facade reference for setup instructions.

Constructor

public function __construct(
    private readonly string $modelId,
    private readonly XAIOptions $options,
    private readonly ?ModelRegistry $registry = null,
)
ParameterTypeDescription
$modelIdstringThe image model identifier, e.g. 'grok-imagine-image-quality'.
$optionsXAIOptionsProvider configuration: base URL, API key, and SDK HTTP dependencies.
$registryModelRegistry|nullOptional 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.
$model->provider(); // 'xai'

modelId(): string

Returns the model identifier that was supplied at construction time.
$model->modelId(); // e.g. 'grok-imagine-image-quality'

capabilities(): array<int, Capability>

Returns the full list of Capability enum cases supported by this model. The method resolves the list in priority order:
  1. Model registry — if a ModelRegistry was injected and contains an entry for this (provider, modelId) pair, that definition’s capability list is used.
  2. Catalog — otherwise the bundled resources/models.json catalog is consulted.
$capabilities = XAI::image('grok-imagine-image-quality')->capabilities();
// [Capability::ImageGeneration, Capability::TextInput, Capability::ImageInput]
The 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:
  1. Configured overrides — capability flags set on the XAIOptions instance.
  2. Model registry — result from the injected ModelRegistry, if present.
  3. Catalog — bundled resources/models.json.
use AiSdk\Capability;

$support = XAI::image('grok-imagine-image-quality')->capability(Capability::ImageGeneration);
$support->isSupported(); // true

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:
    OptionValueEffect
    aspectRatioParameter'aspect_ratio'Sends aspect ratio as aspect_ratio in the request body.
    inferSizeFromAspectRatiofalseDisables automatic size inference from aspect ratio.
    sizeParameternullThe size field is never included in the request.
    seedParameternullThe seed field is never included in the request.
  • POSTs to {baseUrl}/images/generations via the SDK HTTP runner.
  • Deserialises the JSON response with ImageResponseParser::parse().
$result = Generate::image()
    ->model(XAI::image('grok-imagine-image-quality'))
    ->prompt('A futuristic skyline')
    ->count(2)
    ->aspectRatio('16:9')
    ->run();

echo $result->output->base64;
$result->output->save('/tmp/image.png');
You can also pass xAI-specific raw fields (such as resolution) via providerOptions():
$result = Generate::image()
    ->model(XAI::image('grok-imagine-image-quality'))
    ->prompt('A futuristic skyline')
    ->aspectRatio('16:9')
    ->providerOptions('xai', ['raw' => ['resolution' => '2k']])
    ->run();
ParameterTypeDescription
$requestImageRequestThe portable image model request object.
Returns ImageResponse — contains output (with base64 and a save() helper), usage, and providerMetadata.

Endpoint

POST {baseUrl}/images/generations
Default base URL: https://api.x.ai/v1
Full 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 as b64_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.

Build docs developers (and LLMs) love