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.

Azure Foundry pricing requires a caller-declared deployment mapping with its underlying model version, SKU, and Azure resource region. Pass those facts to price_foundry_deployment() as identity={"deployment": "my-deployment", "model": "gpt-6-luna", "version": "2026-09-22", "sku": "GlobalStandard", "region": "eastus"}, with requested_deployment="my-deployment" from the request and token usage. The method checks the declared SKU and requires the requested deployment to match the mapping before applying the verified catalog rate. It does not independently verify the deployment configuration with Azure. A generic provider="azure" call stays unpriced because its deployment type is unknown. Batch and cache-write usage remain partial where the catalog lacks a matching rate.

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

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.5
File Size Uploaded Provenance Actions
metergraph_core-0.9.5.tar.gz 132.3 kB With provenance Details for metergraph_core-0.9.5.tar.gz

Built distribution (wheel)

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

Total release size: 271.6 kB

Release files / metergraph_core-0.9.5.tar.gz

Download URL metergraph_core-0.9.5.tar.gz
Size 132.3 kB
Tags Source
SHA-256 checksum
How to use checksums
25912cd7eb0324afa2ed145f17157ef3cc7243794546f8518f273a4b78540a4e
BLAKE2b-256 checksum
How to use checksums
a75011d4581783a00132346fb5b72ee84e2a0fe3b29318cba5a877dc63c6abfa
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 30, 2026.

Transparency log

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

Download URL metergraph_core-0.9.5-py3-none-any.whl
Size 139.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54a955403f14dfd9bcc2fb07e965b2f30dd9d53314b54fae3c2f0f93b5fff31e
BLAKE2b-256 checksum
How to use checksums
a305282e2bae4f06c25ff61df0a82e9d2de498ae5b272cb22ae4f4ba675554e0
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 30, 2026.

Transparency log

Security for metergraph-core 0.9.5

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.5.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 30, 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.5 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