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.

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.8.29

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.8.29
File Size Uploaded Provenance Actions
metergraph_core-0.8.29.tar.gz 125.6 kB With provenance Details for metergraph_core-0.8.29.tar.gz

Built distribution (wheel)

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

Total release size: 258.5 kB

Release files / metergraph_core-0.8.29.tar.gz

Download URL metergraph_core-0.8.29.tar.gz
Size 125.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a0390f5add63a52fc3ba125dfa3b7ef1cc41cd5bb5bff693c6973ab4343d3155
BLAKE2b-256 checksum
How to use checksums
9db07c74c752511b714972f994b24d8ec309cb0206f34086a3e43c93f94d31b3
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 20, 2026.

Transparency log

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

Download URL metergraph_core-0.8.29-py3-none-any.whl
Size 132.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d884b3edb49df8d49739f26ae57b2d1a0684de2940e40682b78bd9da70ae6925
BLAKE2b-256 checksum
How to use checksums
6c8b2fbb9d234b47366d6c9e73a2d650a347ad3bb184b266a51c4a6220a805eb
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 20, 2026.

Transparency log

Security for metergraph-core 0.8.29

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.8.29.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 20, 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.8.29 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