Search by

adachsoft / model-pricing-http-client

Arkadiusz Adach

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

Issues

pkg:composer/adachsoft/model-pricing-http-client

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-17 23:02 UTC

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_found returns null from findPriceSheet() and estimate().
  • HTTP 422 throws InvalidPricingDataException, using error.message when 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.