adachsoft / model-pricing-source-anthropic
Anthropic model pricing source for model-pricing-lib
Package info
gitlab.com/a.adach/model-pricing-source-anthropic
pkg:composer/adachsoft/model-pricing-source-anthropic
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:25:23 UTC
README
A PriceSourceInterface implementation that retrieves Anthropic's official Markdown pricing page and converts its model prices into validated price sheets for model-pricing-lib.
Features
- Parses standard, batch-processing, and fast-mode prices, including cache prices and context tiers.
- Represents eligible US inference prices as separate pricing components.
- Uses decimal-string arithmetic instead of binary floating-point calculations.
- Fetches pricing through injected PSR-18 and PSR-17 implementations.
Installation
composer require adachsoft/model-pricing-source-anthropic
Requirements
- PHP 8.3 or later
- The BCMath PHP extension
- A PSR-18 HTTP client and a PSR-17 request factory provided by your application
Usage
Create a PSR-18 client and PSR-17 request factory using your application's HTTP libraries, then pass them into the source:
$source = new AnthropicPriceSource(
new AnthropicPricingPageFetcher($httpClient, $requestFactory),
);
$priceSheets = $source->fetchPriceSheets(new DateTimeImmutable());
See the complete usage example for imports and exception handling. The source downloads the official Anthropic pricing page when fetching price sheets.
Development
The test suite uses a Markdown fixture and fake HTTP responses; it does not make network requests.