adachsoft / model-pricing-source-moonshot
Moonshot model pricing source for model-pricing-lib
Package info
gitlab.com/a.adach/model-pricing-source-moonshot
pkg:composer/adachsoft/model-pricing-source-moonshot
v0.1.0
2026-11-17 21:09 UTC
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/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 20:09:28 UTC
README
A model-pricing-lib price source that retrieves Moonshot's public chat pricing page and converts its model prices into validated price sheets. It supports standard and batch pricing, cached-input prices, and cache-write prices where published.
Features
- Fetches the official Moonshot pricing page using PSR-18 and PSR-17 interfaces.
- Parses published model pricing and batch discounts without floating-point arithmetic.
- Returns price sheets compatible with
adachsoft/model-pricing-contracts.
Requirements
- PHP 8.3 or newer.
- The BCMath PHP extension.
- A PSR-18 HTTP client and a PSR-17 request factory supplied by the application.
Installation
composer require adachsoft/model-pricing-source-moonshot
The application must provide a PSR-18 HTTP client and a PSR-17 request factory.
Usage
<?php
declare(strict_types=1);
use AdachSoft\ModelPricingSourceMoonshot\Http\MoonshotPricingPageFetcher;
use AdachSoft\ModelPricingSourceMoonshot\MoonshotPriceSource;
use DateTimeImmutable;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
/** @var ClientInterface $httpClient Configured application PSR-18 client. */
/** @var RequestFactoryInterface $requestFactory Configured PSR-17 request factory. */
$fetcher = new MoonshotPricingPageFetcher($httpClient, $requestFactory);
$source = new MoonshotPriceSource($fetcher);
$priceSheets = $source->fetchPriceSheets(new DateTimeImmutable());
See the usage example for details on consuming the returned sheets.