adachsoft/ai-image-xai

AI image explanation library

Maintainers

Package info

gitlab.com/a.adach/ai-image-xai

Issues

pkg:composer/adachsoft/ai-image-xai

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

v0.2.0 2026-03-19 05:29 UTC

This package is auto-updated.

Last update: 2026-03-19 04:29:22 UTC


README

AI image generator implementation for the X.AI (Grok) API.

Installation

composer require adachsoft/ai-image-xai

Usage

use AdachSoft\AiImageContract\Collections\ImageInputCollection;
use AdachSoft\AiImageContract\Exceptions\AiImageExceptionInterface;
use AdachSoft\AiImageContract\Models\GenerationRequest;
use AdachSoft\AiImageContract\ValueObjects\ImageSize;
use AdachSoft\AiImageContract\ValueObjects\Prompt;
use AdachSoft\AiImageXai\XaiImageGeneratorFactory;

$generator = XaiImageGeneratorFactory::create('your-xai-api-key');

$request = new GenerationRequest(
    prompt: new Prompt('A cute dog with a lion mane'),
    imageInputs: new ImageInputCollection([]),
    size: new ImageSize(1024, 1024),
    options: ['model' => 'grok-imagine-image'],
);

try {
    $response = $generator->generate($request);

    foreach ($response->images as $image) {
        if ($image->url !== null) {
            echo $image->url . PHP_EOL;
        }

        if ($image->b64Json !== null) {
            echo $image->b64Json . PHP_EOL;
        }
    }
} catch (AiImageExceptionInterface $exception) {
    echo $exception->getMessage();
}

Exception model

This adapter follows the adachsoft/ai-image-contract exception model.

  • ContentModerationException is used for moderation and safety filter rejections.
  • RetryableException is used for temporary provider failures such as rate limits, connectivity issues, and transient server errors.
  • GenerationFailedException is used for non-retryable generation failures.