adachsoft / model-pricing-http-client
PSR-18 HTTP client for model pricing catalogs and cost estimation over the model-pricing REST API.
Package info
gitlab.com/a.adach/model-pricing-http-client
pkg:composer/adachsoft/model-pricing-http-client
Requires
- php: ^8.3
- ext-json: *
- adachsoft/model-pricing-contracts: ^0.4
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
Requires (Dev)
- adachsoft/model-pricing-api-bundle: ^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 22:02:29 UTC
README
A PSR-18 adapter that connects the adachsoft/model-pricing-contracts catalog and cost-estimator ports to a model-pricing REST API.
Features
- Provides price catalog lookup and listing through the contracts interfaces.
- Provides cost estimation through the contracts interface.
- Maps API JSON responses to contract DTOs while preserving monetary decimals as strings.
- Encodes URL path segments and query values, and maps API errors to contract exceptions.
Requirements
- PHP 8.3 or later
- A PSR-18 HTTP client
- PSR-17 request and stream factories
Installation
composer require adachsoft/model-pricing-http-client
Install a PSR-18 client and PSR-17 factories supported by your application as well.
Configuration and usage
Configure the API base URL with its route prefix and without a trailing slash. Optional headers, such as an authorization header, are sent with every request.
use AdachSoft\ModelPricingHttpClient\ModelPricingHttpClientConfigDto;
use AdachSoft\ModelPricingHttpClient\ModelPricingHttpClientFactory;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
$httpFactory = new HttpFactory();
$config = new ModelPricingHttpClientConfigDto(
'https://pricing.example.com/api/v1',
['Authorization' => 'Bearer ' . $accessToken],
);
$catalog = ModelPricingHttpClientFactory::createCatalog(
new Client(),
$httpFactory,
$httpFactory,
$config,
);
$estimator = ModelPricingHttpClientFactory::createEstimator(
new Client(),
$httpFactory,
$httpFactory,
$config,
);
The client sends Accept: application/json on all requests and Content-Type: application/json on estimate requests. Catalog lookups use GET /model-pricing/{providerId}/{modelId} and GET /model-pricing?provider_id=...; estimates use POST /model-pricing/estimate.
Error mapping
- HTTP 404 with
error.code=price_sheet_not_foundreturnsnullfromfindPriceSheet()andestimate(). - HTTP 422 throws
InvalidPricingDataException, usingerror.messagewhen available. - PSR-18 client exceptions, invalid JSON, invalid response fields, HTTP 5xx responses, and other HTTP errors throw
PriceCatalogUnavailableException. - Request headers are never added to transport exception messages.