adachsoft / model-pricing-source-openai
Price source for adachsoft/model-pricing-lib that reads the official OpenAI API pricing page.
Package info
gitlab.com/a.adach/model-pricing-source-openai
pkg:composer/adachsoft/model-pricing-source-openai
Requires
- php: ^8.3
- ext-bcmath: *
- ext-json: *
- adachsoft/model-pricing-contracts: ^0.4
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
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.0
- phpstan/phpstan: ^2.3
- phpstan/phpstan-phpunit: ^2.0
- 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:01:45 UTC
README
A price source for adachsoft/model-pricing-lib. It fetches OpenAI's public API pricing page and its referenced pricing bundle, validates the listed model rates, and returns immutable price sheets in USD.
Features
- Supports standard, batch, flex, priority, and ultrafast service tiers.
- Parses short- and long-context pricing, including legacy table rows.
- Preserves decimal prices exactly and rejects incomplete or inconsistent pricing data instead of returning partial results.
- Uses PSR-18 HTTP clients and PSR-17 request factories.
Requirements
- PHP 8.3 or later
- The BCMath and JSON PHP extensions
- A PSR-18 HTTP client and a PSR-17 request factory
Installation
composer require adachsoft/model-pricing-source-openai
Usage
Create an OpenAiPriceSource with a PSR-18 client and PSR-17 request factory, then call fetchPriceSheets() to retrieve validated USD price sheets. See the fetch pricing example for a complete example.