Skip to main content

metergraph-core

Calculate the cost of an LLM call from its model, provider, tokens, region, and date. metergraph-core ships an open, effective-dated model pricing catalog and a deterministic Python cost engine.

Install

python -m pip install metergraph-core

Usage

Use calculate_cost() when you already have token counts:

from metergraph_core import ModelUsage, load_catalog

catalog = load_catalog(region="global")
result = catalog.calculate_cost(
    model="gpt-5.4-mini",
    provider="openai",
    at="2026-08-17T00:00:00Z",
    usage=ModelUsage(input_tokens=1000, output_tokens=200),
)
print(result.status, result.cost, result.currency)

The result identifies the applied model and price. Check status before using its cost as a complete total: missing usage or unsupported rates can make a result partial or unpriced.

Served OpenAI priority/fast and Vertex priority calls use model-specific catalog rates where verified. Priority coverage starts on November 22, 2026. Requested Priority that falls back to standard uses standard pricing. Search fees are priced separately from the token tier.

Choose the API for your input

You have… Start with…
Token counts and a model catalog.calculate_cost(..., usage=ModelUsage(...))
A provider SDK response price_call_from_response(provider, response) for token costs and supported retrieval fees
A normalized SDK or relay record price_call_from_record(record)
Request handlers that need ready-to-use pricing data Catalogs, with one instance shared across handlers
Model identities, executable routes, or candidate lists load_model_registry()

For price lookup, token-only response pricing, missing-data rules, gateway billing evidence, and model metadata, see the pricing and model reference.

Serving real-time requests

Prepare catalogs once before accepting traffic. Request handlers then call catalogs.current() and use the same pricing methods shown above. Choose one of the following lifecycle options.

Let the catalog own its refresh thread

from metergraph_core import Catalogs

catalogs = Catalogs(region="global", refresh_seconds=300)
catalogs.start()
try:
    print(catalogs.current().version)
finally:
    catalogs.stop()

Use your own scheduler or threads

prepare() and refresh() are synchronous and create no threads. Prepare before serving; run refreshes outside request handlers. This example schedules one refresh on an executor owned by the application:

from concurrent.futures import ThreadPoolExecutor
from metergraph_core import Catalogs

catalogs = Catalogs(region="global")
catalogs.prepare()
try:
    with ThreadPoolExecutor(max_workers=1) as executor:
        refresh = executor.submit(catalogs.refresh)
        print(catalogs.current().version)
        refresh.result()
finally:
    catalogs.stop()

Both options enable prepared-only reads. Without either option, current() loads and refreshes on demand. The default source is the bundled catalog; custom loaders can supply changing data. See the lifecycle contract for refresh failures, custom sources, read-only values, and shutdown behavior.

Reference and contributions

  • Pricing and model reference: loading, regional and dated prices, provider responses, retrieval fees, model families, routes, training policy, billing evidence, and reliability.
  • Catalog maintenance: data files and versions, official sources, reviewed deltas, refresh tooling, and provider contributions.
  • Public API exports.

Core contains the shared datasets and pricing rules for Metergraph. Core does not own HTTP routes, database access, authentication, ingestion, or dashboards; these belong to the applications using it.

Metadata

Release files for metergraph-core 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for metergraph-core 0.9.0
File Size Uploaded Provenance Actions
metergraph_core-0.9.0.tar.gz 130.2 kB With provenance Details for metergraph_core-0.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for metergraph-core 0.9.0
File Interpreter ABI Platform Actions
metergraph_core-0.9.0-py3-none-any.whl Python 3 none any Details for metergraph_core-0.9.0-py3-none-any.whl

Total release size: 267.2 kB

Release files / metergraph_core-0.9.0.tar.gz

Download URL metergraph_core-0.9.0.tar.gz
Size 130.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b4532637183eb5ca41ade9f9ca155ccead0cd0b2439217dbb34afb4efc3d840c
BLAKE2b-256 checksum
How to use checksums
b585f6bdcc1563ad8205a5f23abb53427153834fcb5a46e10e24ade3b109c640
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Release files / metergraph_core-0.9.0-py3-none-any.whl

Download URL metergraph_core-0.9.0-py3-none-any.whl
Size 137.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78d073756d3835f992e109d0a9977e9b1b01ae1185b97a3fa454f43c6e228f20
BLAKE2b-256 checksum
How to use checksums
c3ad80b54063e7e23f35d41531ba65256d80d42ac9fe8e9112326e8deb8771d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Security for metergraph-core 0.9.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for metergraph_core-0.9.0.tar.gz

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 Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page