adachsoft / model-pricing-source-xai
xAI model pricing source for model-pricing-lib
Package info
gitlab.com/a.adach/model-pricing-source-xai
pkg:composer/adachsoft/model-pricing-source-xai
Requires
- php: ^8.3
- ext-bcmath: *
- adachsoft/model-pricing-contracts: ^0.4
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
Requires (Dev)
- adachsoft/model-pricing-lib: ^0.1.0
- adachsoft/php-code-style: ^0.7.3
- friendsofphp/php-cs-fixer: ^3.95
- guzzlehttp/psr7: ^2.7
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^12.5
- rector/rector: ^2.8
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-17 18:52:44 UTC
README
This library implements the PriceSourceInterface contract for xAI. It fetches xAI's official Markdown pricing page and builds validated model price sheets for use with model-pricing-lib.
Requirements
- PHP 8.3 or newer
- BCMath extension
- A PSR-18 HTTP client and a PSR-17 request factory
Features
- Parses per-million-token input, cached-input, and output prices from the Text API pricing table.
- Supports short- and long-context rates, Batch API discounts, and Priority Processing multipliers.
- Uses PSR-18 HTTP clients and PSR-17 request factories, allowing applications to choose their HTTP implementation.
Image, video, voice, tool, Grok 4.7 Fast, and US regional endpoint pricing are not included.
Installation
composer require adachsoft/model-pricing-source-xai
Usage
Provide a PSR-18 HTTP client and a PSR-17 request factory, then create the source:
use AdachSoft\ModelPricingSourceXai\Http\XaiPricingPageFetcher;
use AdachSoft\ModelPricingSourceXai\XaiPriceSource;
use DateTimeImmutable;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
$fetcher = new XaiPricingPageFetcher($httpClient, $requestFactory);
$source = new XaiPriceSource($fetcher);
$priceSheets = $source->fetchPriceSheets(new DateTimeImmutable());
See usage examples for an example and a custom pricing page URL.
Testing
Tests use a checked-in pricing fixture and fake PSR-18 responses. They do not make network requests.