MAQPNADocs

Usage metering and billing

Count usage per tenant from the audit ledger and sessions, produce signed usage reports with a FOCUS cost export, verify them, and export pseudonymised reports for an air-gapped true-up.

flowchart LR
  L[(Audit ledger<br/>calls · tokens · approvals)] --> B[maqpna usage buckets<br/>hourly, per tenant]
  K[AgentSessions<br/>sandbox time] --> B
  B --> R[maqpna usage report<br/>signed report.json<br/>report.focus.csv]
  R --> V[maqpna usage verify<br/>signature + totals + ledger head]
  R --> X[maqpna usage export<br/>pseudonymised, for true-up]
  L --> F[maqpna costs focus<br/>per-call FOCUS export]

Goal#

Measure what each tenant used, turn it into a report your customer (or MAQPNA) can check independently, and feed it into billing or FinOps tools.

Usage is metered units for billing:

Unit Source SKU in reports
Sandbox time AgentSession status (readyAt to outcome.finishedAt, or now while running), and finished sessions recorded by the gateway in the ledger sandbox-vcpu-hours
Governed calls Allowed tool calls in the audit ledger. Denied calls are recorded but not billed governed-calls
Model tokens Model calls through the gateway's model route model-tokens
Approvals Calls held for approval approvals

Prerequisites#

  • The maqpna CLI and either a gateway with an access token (auditor or admin) or a copy of the ledger file.
  • For sandbox time and per-tenant grouping: cluster access (AgentSession and Tenant objects). Without it, pass --no-sessions: you get calls, tokens and approvals only, and no tenant mapping.
  • A signing key you hold. Reports are signed with the audit-checkpoint key, so the same public key (/v1/audit/jwks) verifies checkpoints and reports.
Signed usage report.cast

Steps#

1. Look at hourly buckets#

Offline, from a ledger file (a local MAQPNA writes it to .maqpna/audit.jsonl):

maqpna usage buckets --ledger .maqpna/audit.jsonl --no-sessions

Output from a local run:

HOUR              TENANT  NAMESPACE  KIND   SKU   QUANTITY  UNIT
2026-10-03 03:00  -       dev        model  stub  52        Tokens
2026-10-03 03:00  -       dev        tool   echo  4         Requests
2026-10-03 03:00  -       team-a     tool   echo  1         Requests

Against a gateway and cluster, for one tenant over the last day:

maqpna usage buckets --from 24h --tenant acme

--from takes a duration (24h) or an RFC 3339 time; --to defaults to now. --format csv writes hour,tenant,namespace,kind,sku,unit,quantity; -o json gives the buckets as JSON. Usage outside any tenant shows - as the tenant.

2. Choose the signing key#

--key takes a key URI: a file path or file:///abs/path (Ed25519 PKCS#8 PEM), pkcs11:… or kms://<provider>/<key-id>. The release binaries include only the file backend; pkcs11: and kms:// need a backend built into your binary. In production, use the audit-checkpoint key from the Secret named in audit.checkpointSigning.secretName (key audit-signing.pem). To try it locally, generate one:

maqpna keygen -out keys --name checkpoint
private key: keys/checkpoint.key
public key:  keys/checkpoint.pub
kid:         9FHvKLplpeVjzWvxxFWPh1ehLcgi_pTY8-7Q7coiPjE

3. Produce a signed report#

maqpna usage report --period 2026-10 --key keys/checkpoint.key \
  --ledger .maqpna/audit.jsonl --no-sessions --installation-id lab-fra-1 --out reports

Output from a local run:

! Node high-water mark unavailable: kubeconfig: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
Usage report 2026-10-01 to 2026-11-01 (UTC) [partial: period not over]
installation lab-fra-1, licence none
ledger head seq 7 hash 81dff220de43203a25b8270b39c4ad65bc6a1eafb00e46d521a4a8b87c8328c8
billable nodes (high-water): unavailable
TENANT       VCPU-HOURS  SANDBOX-HOURS  GOVERNED-CALLS  MODEL-TOKENS  APPROVALS  LIST USD
(no tenant)  0.0000      0.0000         5               52            0          0.00
TOTAL        0.0000      0.0000         5               52            0          0.00
signed with kid 9FHvKLplpeVjzWvxxFWPh1ehLcgi_pTY8-7Q7coiPjE; wrote reports/report.json, reports/report.focus.csv, reports/report.summary.txt

The warning appears because there was no cluster: the billable-node mark comes from the ConfigMap maqpna-usage-nodes (see licensing).

The three files:

File Contents
report.json Report maqpna.com/usage-report/v1: period, partial (period not over yet), installationId, ledgerHead (seq and hash), nodes, cpu, totals, per-tenant totals and the hourly buckets, signed with an Ed25519 detached JWS over the canonical JSON (signature.jws)
report.focus.csv One FOCUS 1.2 row (FOCUS is the FinOps cost-export format) per tenant and SKU: list price × quantity, with x_MaqpnaInstallationId, x_MaqpnaLicenseId and x_MaqpnaLedgerHeadSeq
report.summary.txt The table above

Options:

  • --period YYYY-MM for a calendar month (UTC), or --from and --to (RFC 3339 or YYYY-MM-DD, end exclusive).
  • --tenant acme for one tenant's report.
  • --installation-id (or MAQPNA_INSTALLATION_ID); the default is the UID of the kube-system namespace.
  • --license FILE puts your licence ID in the report.
  • --default-vcpu (default 1) is used for sandbox time without CPU data; the report is then flagged estimated.

4. Price it with your own price list#

By default the FOCUS export uses the Operator edition list prices. Pass a price file to bill at your own prices. SKUs you leave out keep the defaults:

# prices.yaml
currency: EUR
skus:
  governed-calls: {unitPrice: 0.05, per: 1000}
  sandbox-vcpu-hours: {unitPrice: 0.015, per: 1}
maqpna usage report --period 2026-10 --key keys/checkpoint.key --ledger .maqpna/audit.jsonl \
  --no-sessions --installation-id lab-fra-1 --price-file prices.yaml --out reports-eur

The summary's last column becomes LIST EUR, and the FOCUS rows carry BillingCurrency EUR. Valid SKUs are sandbox-vcpu-hours, governed-calls, model-tokens and approvals; an unknown SKU or a negative price is an error.

5. Verify a report#

Anyone with the public key can check a report offline:

maqpna usage verify reports/report.json --pubkey keys/checkpoint.pub --ledger .maqpna/audit.jsonl
OK: reports/report.json: signature valid (kid 9FHvKLplpeVjzWvxxFWPh1ehLcgi_pTY8-7Q7coiPjE), totals match 3 buckets
period 2026-10-01T00:00:00Z to 2026-11-01T00:00:00Z, installation lab-fra-1: 0.0000 vCPU-hours, 5 governed calls, 52 model tokens, 0 approvals
ledger head seq 7 matches .maqpna/audit.jsonl

verify checks the signature, recomputes the totals from the buckets and, with --ledger, checks the report's ledger head against a ledger copy. Use --jwks with the gateway's /v1/audit/jwks (a URL or a file) instead of --pubkey.

A report changed after signing (here governedCalls edited from 5 to 2) fails with exit status 3:

TAMPERED: t.json: usage report: invalid signature: kid "9FHvKLplpeVjzWvxxFWPh1ehLcgi_pTY8-7Q7coiPjE"

6. Export for an air-gapped true-up#

For a licence true-up without any network connection, export the signed report with tenant, namespace and SKU names pseudonymised. Nothing is sent; you hand over the file:

maqpna usage export --period 2026-10 --key keys/checkpoint.key --ledger .maqpna/audit.jsonl \
  --no-sessions --installation-id lab-fra-1 --out usage-2026-10.json
! Node high-water mark unavailable: kubeconfig: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
signed with kid 9FHvKLplpeVjzWvxxFWPh1ehLcgi_pTY8-7Q7coiPjE; wrote usage-2026-10.json
tenant, namespace and SKU names are pseudonymized; nothing was sent (upload the file for the true-up)

The file has "pseudonymized": true and verifies with maqpna usage verify. export writes the signed JSON only, so it does not take --price-file. Sending the report online is not built.

7. Export per-call costs (FOCUS)#

For FinOps tools, maqpna costs focus exports token, tool-call and sandbox spend as FOCUS 1.2 cost-and-usage rows, per charge period, tenant (SubAccountId is the namespace), agent, session, user and model:

maqpna costs focus --gateway "$MAQPNA_GATEWAY_URL" --since 2026-09-01T00:00:00Z --format json --out costs.json
maqpna costs focus --ledger .maqpna/audit.jsonl --pricing-file pricing.json --tenants-file tenants.json --currency EUR --out costs.csv
Column Value
ChargeCategory / ChargeFrequency Usage / Usage-Based
ServiceName MAQPNA Model Gateway, MAQPNA Tool Gateway or MAQPNA Agent Sandbox (ServiceCategory AI and Machine Learning, subcategory Generative AI for tokens)
ResourceId / ResourceType ns/<namespace>/agent/<agent>/session/<session> / AgentSession
SkuId / SkuMeter / SkuPriceId model:<model> / Input Tokens or Output Tokens / model:<model>:input
ConsumedQuantity / ConsumedUnit tokens / Tokens
PricingQuantity / PricingUnit tokens ÷ 1000 / 1000 Tokens
ListUnitPrice, ContractedUnitPrice price per 1000 tokens, so ListUnitPrice × PricingQuantity = ListCost
BilledCost = EffectiveCost = ListCost = ContractedCost metered cost from the ledger (no commitment discounts)
BillingCurrency the gateway's budgetCurrency (offline: --currency, else the pricing file's currency, else USD)
Tags maqpna.com/namespace, tenant, agent, session, user, model
x_Maqpna* agent, session, user, tenant, charge kind, event count, FOCUS version

Input and output tokens become separate rows when the pricing table prices the model (always on the gateway; --pricing-file offline). The ledger's recorded cost is split in the ratio of the table's input and output prices, so rows always sum to what was metered. Without a price, one Tokens row carries the blended unit price. GPU-hours are not exported yet: agent sessions do not record GPU requests or DRA claims.

--period sets the charge-period granularity (default 1 h). Running totals and windows are in maqpna costs summary:

maqpna costs summary --scope agent --window month
month window 2026-10 (2026-10-01T00:00:00Z to 2026-11-01T00:00:00Z, UTC)
SCOPE  KEY              COST USD  TOOL CALLS  MODEL CALLS  IN TOKENS  OUT TOKENS
agent  dev/coder        0         4           1            8          44
agent  team-a/reviewer  0         1           0            0          0

Costs are what you configured in the gateway's pricing; budgets are covered in budgets and cost limits.

8. Energy and carbon#

MAQPNA can add an estimate of the energy and emissions of each session's model calls to the FOCUS export and to maqpna session cost. Nothing here is measured. None of the metering sources MAQPNA reads (the audit ledger, sessions, llamay) records GPU or node energy, so every figure comes from token counts and published coefficients, and every row says so (x_EnergyMethod estimated). Estimates are off by default, so the export does not change until you turn them on.

Turn them on in the gateway (gateway.json), with the built-in table or your own:

"energy": {"enabled": true}
"energy": {"file": "/etc/maqpna/energy.json", "defaultRegion": "EU-DE"}

Offline, from a ledger file:

maqpna costs focus --ledger .maqpna/audit.jsonl --energy --energy-region EU-DE --out costs.csv
maqpna costs focus --ledger .maqpna/audit.jsonl --energy-file energy.json --out costs.csv
maqpna session cost dev-932622fb      # adds an "energy" block when the gateway has an energy model

Method. For each model call:

IT Wh       = input tokens / 1000 × whPer1kInputTokens + output tokens / 1000 × whPer1kOutputTokens + whPerRequest
facility Wh = IT Wh × PUE              (not applied when the coefficient already includes data-centre overhead)
gCO2e       = facility Wh / 1000 × carbon intensity of the call's region (gCO2e/kWh)

The region comes from the call's ledger record: first the jurisdiction the identity broker verified for the session (substrateJurisdiction, from an identity check: its country, else its region), then the jurisdiction extension, then region. A call with neither uses the energy block's defaultRegion, then the energy file's defaultRegion, then the gateway's sovereignty jurisdiction. Lookup is case-insensitive. It tries the region itself, then an alias, then each parent of a hierarchical code. Aliases cover cloud regions (eu-central-1 → DE, europe-west4 → NL, westeurope → NL) and EU jurisdictions (EU-DE → DE). Parents run from EU-DE-BY to EU-DE to EU, or from us-east-1 to US. A region with no entry gets energy but no carbon: MAQPNA does not fall back to the default region or a world average.

Columns. These are custom columns with the x_ prefix FOCUS reserves, because FOCUS 1.2 defines no sustainability or emissions columns. They come after the existing columns, which do not change:

Column Value
x_EnergyKWh facility energy of the row, kWh
x_CarbonKgCO2e emissions, kgCO2e (location-based: grid average, no renewable certificates)
x_CarbonIntensityGPerKWh the intensity used (energy-weighted when the row's calls ran in several regions)
x_CarbonRegion the intensity table key, for example DE, or mixed
x_PUE the PUE applied (1 when the coefficient includes overhead)
x_EnergyMethod estimated, none (a model without a coefficient) or empty (tool and sandbox rows)
x_EnergyModelVersion the table's version, for example maqpna-default-2026-10
x_EnergySource where the coefficient comes from
x_CarbonIntensitySource where the intensities come from

When a call is split into input and output token rows, its energy is split too: input tokens and the per-request energy go to the input row, output tokens to the output row. The two rows add up to the call's estimate. Tool-call and sandbox rows have no energy model and stay empty.

session cost (GET /v1/sessions/{id}/cost?energy=1) adds the session's energyWh and carbonKgCO2e. It also gives the method, complete (true when every model call had a coefficient), estimatedCalls, unestimatedCalls, unestimatedModels, the energyModel version, the coefficient sources and the regions. It reads the session's own ledger records, so it is computed only when asked for and does not include forked sessions.

Unknown models get no estimate. A model without a coefficient has empty energy and carbon columns (x_EnergyMethod none), and its session is marked complete: false. MAQPNA never applies a default coefficient to it. Most hosted models, Claude models among them, have no published per-token energy figure, so they are not in the built-in table. Add your own coefficients for them.

The built-in table (maqpna-default-2026-10). Every entry is a published estimate:

Models Coefficient Source and derivation
gpt-4o, gpt-4o-2* (not gpt-4o-mini) 0.21 Wh / 1k input, 0.6 Wh / 1k output, overhead included Epoch AI, J. You, How much energy does ChatGPT use? (7 Feb 2025). A typical GPT-4o query of about 500 output tokens uses about 0.3 Wh, and about 2.4 Wh with 10k input tokens. Epoch counts server and data-centre overhead in its per-GPU power, so PUE is not applied again. Energy grows faster than linearly with very long inputs (almost 40 Wh at 100k tokens, per Epoch), so long-context calls are underestimated.
gemini-* 0.24 Wh per request, overhead included Elsworth et al., Google, Measuring the environmental impact of delivering AI at Google Scale (Aug 2025). The median Gemini Apps text prompt uses 0.24 Wh, including idle capacity, host and data-centre overhead. No per-token figure is published, so every call counts as one median prompt, however long.
*llama*65b*, *llama*70b* 1 Wh / 1k output tokens, GPU only (PUE applied) Samsi et al., From Words to Watts: Benchmarking the Energy Costs of Large Language Model Inference (2023). LLaMA-65B uses about 3-4 J per output token, measured with DCGM on V100 and A100 GPUs, and 3.6 J per token is 1 Wh per 1000 tokens. This is GPU energy only, measured with short benchmark prompts, so input tokens are not counted separately. Modern, well-batched H100 serving is probably more efficient.
Setting Default Source
PUE 1.54 Uptime Institute, Global Data Center Survey 2025: the global average annual PUE. Hyperscale fleets report much lower values (about 1.1), so set pue per coefficient for providers that publish theirs.
Carbon intensity 2025 annual averages, gCO2e/kWh, rounded: WORLD 458, EU 210, AT 117, BE 150, CZ 401, DE 330, DK 114, ES 154, FI 57, FR 41, IE 257, IT 285, NL 254, PL 589, PT 128, SE 35, CH 39, GB 217, NO 28, US 384, CA 191, BR 110, AU 525, CN 525, IN 670, JP 477, KR 417, SG 497 Ember (2026), via Our World in Data, Carbon intensity of electricity generation (updated 30 June 2026, read October 2026). These are national annual averages. The actual intensity depends on the hour and the local grid and can differ several-fold, and a national average is coarse for a large grid such as US.

Your own table (energy.file, --energy-file). Every coefficient needs a source. With includeDefaults, the built-in entries stay in the table and your own entries take precedence:

{"version": "acme-2026-10",
 "includeDefaults": true,
 "models": {"qwen3-coder": {"whPer1kInputTokens": 0.05, "whPer1kOutputTokens": 0.4, "source": "acme bench, H100, 2026-09"},
            "provider-model-*": {"whPer1kInputTokens": 0.2, "whPer1kOutputTokens": 0.8, "facilityIncluded": true, "source": "provider report 2026"}},
 "pue": 1.2,
 "carbonIntensityGPerKWh": {"DE": 330},
 "regionAliases": {"onprem-fra": "DE"},
 "defaultRegion": "EU-DE",
 "carbonIntensitySource": "Ember 2025 annual averages"}

Model keys are exact names or globs (* and ?, case-insensitive). * also matches / and :, so *llama*70b* matches both meta-llama/Llama-3.3-70B-Instruct and llama3.1:70b. An exact name wins over a glob, and a more specific glob over a less specific one. whPerRequest adds a fixed energy per call, facilityIncluded skips PUE, and pue overrides the table's PUE for one coefficient. Negative numbers and a PUE below 1 are rejected.

Limitations.

  • These are estimates, not measurements. The published figures differ in scope (GPU only, whole server, or whole data centre) and in hardware, batching and prompt length. Read them as orders of magnitude, and compare sessions only within one table version.
  • Only model calls are estimated. MCP tool servers, sandboxes, the gateway itself, networking and embodied (manufacturing) emissions are not.
  • Emissions use location-based annual averages. They are not market-based (renewable energy certificates and power purchase agreements are ignored) and not hourly.
  • Measured GPU energy for self-hosted (llamay) inference is not used, because no metering source records it yet. Calls with measured energy could later be marked measured instead of estimated.
  • The report.focus.csv of maqpna usage report does not have the energy columns.

Verify#

  • maqpna usage verify report.json --pubkey PUB prints OK and exits 0.
  • The report's ledgerHead matches maqpna audit verify on the same ledger (see audit ledger and evidence).
  • The FOCUS CSV imports into your FinOps tool with currency and SKU columns filled.
  • With energy estimates on, the rows of models in your table have x_EnergyMethod estimated and an x_EnergyKWh.

Troubleshooting#

Symptom Cause Fix
sessions need cluster access (or --no-sessions) No kubeconfig and no --no-sessions Configure the cluster context, or add --no-sessions
! Node high-water mark unavailable No cluster, or the operator has not written maqpna-usage-nodes yet Run with cluster access; the report is still signed
--tenant reports zero --no-sessions skips the Tenant objects, so no namespace maps to a tenant Run with cluster access
price file: unknown SKU A key in skus is not one of the four SKUs Use sandbox-vcpu-hours, governed-calls, model-tokens or approvals
TAMPERED: … invalid signature The report was changed, or you used the wrong public key Compare the kid with your key's; re-run the report
Report flagged estimated Sandbox time without CPU data used --default-vcpu Set CPU requests on the agents' sandboxes
x_EnergyMethod is none The model has no energy coefficient Add it, with its source, to your energy file. MAQPNA does not guess
x_EnergyKWh is set but x_CarbonKgCO2e is empty The call's region has no carbon intensity Add the region to carbonIntensityGPerKWh or regionAliases, or set defaultRegion for sessions without a region

Next steps#

Last updated