Search by

adachsoft / model-pricing-source-xai

Arkadiusz Adach

xAI model pricing source for model-pricing-lib

Package info

gitlab.com/a.adach/model-pricing-source-xai

Issues

pkg:composer/adachsoft/model-pricing-source-xai

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-17 19:50 UTC

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.