adachsoft / model-pricing-api-bundle
Symfony bundle exposing AI model price sheets and cost estimates over a REST API, plus price sync console command.
Package info
gitlab.com/a.adach/model-pricing-api-bundle
Type:symfony-bundle
pkg:composer/adachsoft/model-pricing-api-bundle
Requires
- php: ^8.3
- adachsoft/model-pricing-contracts: ^0.4
- adachsoft/model-pricing-lib: ^0.1.0
- symfony/config: ^7.4 || ^8.0
- symfony/console: ^7.4 || ^8.0
- symfony/dependency-injection: ^7.4 || ^8.0
- symfony/framework-bundle: ^7.4 || ^8.0
- symfony/http-foundation: ^7.4 || ^8.0
- symfony/http-kernel: ^7.4 || ^8.0
- symfony/routing: ^7.4 || ^8.0
Requires (Dev)
- adachsoft/php-code-style: ^0.7.3
- friendsofphp/php-cs-fixer: ^3.95
- 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 21:31:28 UTC
README
A Symfony bundle exposing the model-pricing catalog and estimator as JSON endpoints. It uses the JSON price-sheet repository from adachsoft/model-pricing-lib and provides synchronization and inspection console commands.
Configuration
Register AdachSoft\ModelPricingApiBundle\ModelPricingApiBundle in the Symfony bundle list and configure the required JSON storage directory:
model_pricing:
route_prefix: /api/v1
storage_dir: '%kernel.project_dir%/var/model_pricing'
provider_cost_journal: '%kernel.project_dir%/var/log/provider_cost_checks.jsonl'
The route prefix defaults to /api/v1. Import the route resource type model_pricing_api from the application kernel:
$routes->import('.', 'model_pricing_api');
The bundle autoconfigures each service implementing AdachSoft\ModelPricingContracts\Sync\PriceSourceInterface with the model_pricing.price_source tag. It does not register a provider-specific source; applications may install and register sources independently.
HTTP API
All routes are below the configured prefix:
GET /model-pricing?provider_id=openailists currently effective price sheets.provider_idis optional.GET /model-pricing/{providerId}/{modelId}?at=2026-01-01T00:00:00Zreturns the effective sheet for a provider and model. Model identifiers may contain letters, digits,.,_,:, and-.POST /model-pricing/estimateestimates the cost from disjoint billable usage.
Example estimate request:
{
"provider_id": "openai",
"model_id": "gpt-6-luna",
"usage": {
"items": {"input": 1000, "input_cached": 0, "output": 200},
"context_input_tokens": 1000
},
"context": {"service_tier": "flex"},
"at": null
}
Estimate responses contain decimal amounts as strings, along with the currency, completeness flag, priced lines, unpriced kinds, effective sheet timestamp, and warnings. Missing sheets return HTTP 404 with error.code set to price_sheet_not_found. Invalid requests return HTTP 422; unavailable catalogs return HTTP 503.
Console commands
php bin/console model-pricing:syncsynchronizes every tagged source. Use--provider=<id>to select one provider. A source failure is reported on stderr while remaining sources continue; the command exits with code 1 if any source failed, or code 2 for an unknown provider.php bin/console model-pricing:show <provider> <model> [--at=<ISO-8601>]displays the selected sheet's component kinds, units, prices, and conditions.php bin/console model-pricing:reconcile <provider> [--from=YYYY-MM-DD] [--to=YYYY-MM-DD] [--threshold=3] [--format=table|json] [--show-lines]fetches billed lines and compares them with the effective catalog prices. The half-open date range is in UTC;--fromdefaults to 30 days ago at 00:00 UTC and--todefaults to tomorrow at 00:00 UTC. The table separates price coverage from deviation and lists unpriced amounts;--show-linesadds all priced lines. JSON output contains the complete report with monetary values as decimal strings. The command exits with code 0 when the report is within threshold, code 1 on a source failure or price deviation, and code 2 for an unknown provider or invalid input. Unpriced items are reported but do not cause failure.php bin/console model-pricing:verify-provider-cost [--from=YYYY-MM-DD] [--to=YYYY-MM-DD] [--provider=<id>] [--tolerance=0.005] [--format=table|json] [--show-mismatches]compares recorded response estimates with provider-reported costs from the JSONL journal configured byprovider_cost_journal(default:%kernel.project_dir%/var/log/provider_cost_checks.jsonl). The half-open date range is in UTC;--fromdefaults to 30 days ago at 00:00 UTC and--todefaults to tomorrow at 00:00 UTC. Output groups totals by provider and model;--show-mismatchesincludes response-level details. An empty journal is reported clearly and exits with code 0. The command exits with code 0 when all checks are within tolerance, code 1 when mismatches exist, and code 2 for invalid input.
Example:
$ php bin/console model-pricing:reconcile openai --from=2026-01-01 --to=2026-02-01
Reconciliation summary
| Billed | Covered | Ours | Coverage % | Deviation % | Status |
| 0.25 | 0.25 | 0.25 | 100.0000 | 0.0000 | OK |
Mismatches: none
Unpriced lines: none