metergraph-core
Reusable catalog and deterministic billing engine for MeterGraph.
metergraph-core owns the public effective-dated model catalog and the pricing
logic shared across MeterGraph systems: catalog parsing and validation, provider
and model alias resolution, channel and region selection, input/output/cache/
batch/long-context pricing rules, deterministic cost calculation with reason
codes, stable logical price identifiers, and catalog version and content-hash
reporting. It also owns the pure decision that selects a qualified
gateway-reported charge or a catalog estimate as the effective call cost.
It does not own HTTP routes, database access, migrations, authentication, tenancy, ingest, dashboard code, or any hosted-only concern, and it never reads server environment variables.
Install
python -m pip install metergraph-core
Usage
from datetime import datetime, timezone
from metergraph_core import load_catalog
catalog = load_catalog(region="global")
result = catalog.snapshot.cost(
provider="openai",
model="gpt-5.4-mini",
at=datetime(2026, 8, 17, tzinfo=timezone.utc),
input_tokens=1000,
output_tokens=200,
)
print(result.canonical_model, result.price_id, result.cost_usd, result.status)
load_catalog() loads the catalog bundled in the installed package. Pass an
explicit path for tests or a self-hosted catalog replacement. The returned
LoadedCatalog exposes the declared catalog version, the SHA-256
content_hash of the loaded bytes, the parsed document, and the immutable
snapshot used for pricing.
Planning and evaluation systems that know the deployment channel before making a call can resolve the exact effective price without emulating a provider response:
price = catalog.snapshot.resolve_price(
model="openai/gpt-5.6-luna",
channel="vercel-ai-gateway",
at=datetime(2026, 8, 17, tzinfo=timezone.utc),
)
if price is not None:
print(
price.canonical_model,
price.price.id,
price.price.input_per_mtok,
price.price.source_url,
)
Resolution accepts canonical IDs and channel-scoped aliases, normalizes case
and surrounding whitespace, applies the configured region fallback and
effective-date windows, and returns None when no exact model/channel price
exists. It never substitutes a direct-provider price for a gateway price.
LoadedCatalog.currency is currently always USD, and
LoadedCatalog.pricing_verified_at records when the bundled catalog was last
checked against its linked provider sources.
Billing evidence
Servers can pass content-blind, already-extracted gateway fields through the shared trust boundary and combine them with a catalog result:
from metergraph_core import normalize_gateway_evidence, resolve_billing
evidence = normalize_gateway_evidence({
"gateway": "openrouter",
"endpoint": "chat.completions",
"reported_cost_usd": "0.00482",
"reported_cost_source": "openrouter.usage.cost",
})
decision = resolve_billing(result, evidence)
print(decision.cost_usd, decision.cost_provenance)
The initial qualified contract is OpenRouter Chat Completions. A finite,
non-negative openrouter.usage.cost value, including zero, takes precedence
over a catalog estimate. The decision retains both values and never adds the
separately reported upstream inference cost to the OpenRouter account charge.
Unsupported or malformed evidence falls back to the catalog result.
The billing module validates only gateway, endpoint, fixed source names, and decimal cost values. It does not inspect provider response content or own SDK capture, HTTP, timestamps, trace context, persistence, or tenant behavior.
Public API
from metergraph_core import (
Alias,
BillingDecision,
CatalogError,
CatalogSnapshot,
CostResult,
GatewayBillingEvidence,
LoadedCatalog,
Price,
ResolvedPrice,
load_catalog,
normalize_gateway_evidence,
parse_catalog,
resolve_billing,
)
Catalog maintenance
The only manually maintained public catalog lives at
src/metergraph_core/data/prices.yaml. Every record requires its provider
source URL and effective date. Corrections close or add effective windows; they
never rewrite historical prices in place. A catalog change updates the declared
catalog version and produces a patch release of metergraph-core. Software
version and catalog version are separate values because code and price data have
different lifecycles.
Release files for metergraph-core 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| metergraph_core-0.2.0.tar.gz | 15.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| metergraph_core-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.0 kB
Release files / metergraph_core-0.2.0.tar.gz
| Download URL | metergraph_core-0.2.0.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
58fb3cd3711db885325e8e8f81e4c9309953f9f4f1b73246cd7700232002d51d
|
|
BLAKE2b-256 checksum How to use checksums |
a8da0a86abeaca958f728bda89e12e8abcc1ec7eacaa8d9f94dd4237cd741382
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.
Transparency logRelease files / metergraph_core-0.2.0-py3-none-any.whl
| Download URL | metergraph_core-0.2.0-py3-none-any.whl |
|---|---|
| Size | 15.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc94ddc681f1e0fb9ae0ba228849dfc57bf92731a63730d1c3389b875939ec45
|
|
BLAKE2b-256 checksum How to use checksums |
8f1a9f0c47d96f8509b09eb0a5df87cb98994b7315e4b6459ad3e8016c2947d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.
Transparency log