Package com.tnsai.llm.observability
Class JsonLLMPricingRegistry
java.lang.Object
com.tnsai.llm.observability.JsonLLMPricingRegistry
- All Implemented Interfaces:
LLMPricingRegistry
LLMPricingRegistry that loads rates from a classpath JSON file
(issue #79).
Default rate card ships at /pricing/2026-05.json bundled in
this module. Consumers wanting enterprise-negotiated rates can ship
their own JSON and call fromClasspath(String) with their
resource path. The JSON shape is:
{
"version": "2026-05",
"providers": {
"openai": {
"gpt-4o": {
"prompt_per_1k": 0.0025,
"cached_per_1k": 0.00125,
"completion_per_1k": 0.01,
"reasoning_per_1k": null
},
...
},
"ollama": { "*": { ... } }
}
}
The "*" model key acts as a catch-all for that provider —
useful for self-hosted providers (Ollama, vLLM) where every model has
the same operational cost (zero, in the local case).
Internally delegates to InMemoryLLMPricingRegistry: the JSON
loader is a thin parser that wires rates into the in-memory adapter.
- Since:
- 0.9.0 (issue #79)
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonLLMPricingRegistryLoad the bundled default rate card (DEFAULT_RESOURCE).estimate(String provider, String model, TokenUsage usage) Compute a USD cost estimate for the givenusageunder the namedprovider+model.static JsonLLMPricingRegistryfromClasspath(String resourcePath) Load a rate card from a classpath resource.Stable version identifier of the pricing data — a date string, a content hash, whatever survives "what was the rate when this call was billed?"
-
Field Details
-
DEFAULT_RESOURCE
Default rate card shipped in this module.- See Also:
-
-
Method Details
-
defaultRegistry
Load the bundled default rate card (DEFAULT_RESOURCE). -
fromClasspath
Load a rate card from a classpath resource.- Throws:
IllegalStateException- if the resource is missing or malformed
-
estimate
Description copied from interface:LLMPricingRegistryCompute a USD cost estimate for the givenusageunder the namedprovider+model. Implementations MUST return a non-nullCostEstimate; if the pair is unknown, return a zero estimate stamped withLLMPricingRegistry.tableVersion()so the caller still sees provenance.- Specified by:
estimatein interfaceLLMPricingRegistry
-
tableVersion
Description copied from interface:LLMPricingRegistryStable version identifier of the pricing data — a date string, a content hash, whatever survives "what was the rate when this call was billed?" audits. Embedded in everyCostEstimatethe registry produces so downstream cost-aggregation can detect rate-table drift.- Specified by:
tableVersionin interfaceLLMPricingRegistry
-