adachsoft/ai-model-list-provider-xai

XAI (Grok) SPI provider for AdachSoft AI Model List.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/adachsoft/ai-model-list-provider-xai

v0.1.0 2025-10-19 16:08 UTC

This package is not auto-updated.

Last update: 2025-10-19 19:41:57 UTC


README

Provider implementation for adachsoft/ai-model-list using the XAI (Grok) API.

  • Provider ID: xai
  • HTTP endpoint: GET https://api.x.ai/v1/models with header Authorization: Bearer <apiKey>
  • Default timeout: 10.0s (internal, via factory)

Installation (local path)

{
  "repositories": [
    { "type": "path", "url": "../ai-model-list-provider-xai", "options": { "symlink": true } }
  ],
  "require": {
    "adachsoft/ai-model-list-provider-xai": "*"
  }
}

Library composer.json should contain:

{
  "name": "adachsoft/ai-model-list-provider-xai",
  "autoload": { "psr-4": { "AdachSoft\\AIModelListProviderXai\\": "src/" } }
}

Then run in the consumer project:

  • composer update adachsoft/ai-model-list-provider-xai

Quick Start (Factory)

use AdachSoft\AIModelList\PublicApi\Builder\AiModelCatalogFacadeBuilder;
use AdachSoft\AIModelListProviderXai\Factory\XaiSpiProviderFactory;

$provider = XaiSpiProviderFactory::create($apiKey);
$facade = (new AiModelCatalogFacadeBuilder())
    ->withSpiProvider($provider)
    ->build();

$models = $facade->listModels('xai'); // returns PublicApi\Collection\ModelDefinitionCollection
foreach ($models as $model) {
    echo $model->modelId, "\n"; // modelId is a string in Public API DTO
}

CLI example

  • Create a .env file in the project root:
XAI_API_KEY=your_real_api_key
  • Run: php bin/xai-list-models

The script reads .env, builds the provider via the factory, and prints model IDs using adachsoft/console-io output.

Notes

  • Endpoint is fixed to https://api.x.ai (no configurable base URL).
  • Capabilities mapping (heuristic): CHAT for all; IMAGE when model id contains vision; AUDIO/EMBEDDING not supported.
  • Configuration DTO validates primitives in the constructor; base URL is not exposed.
  • Exception classes are not covered by unit tests per project guidelines.