Tiered usage pricing: graduated or volume tiers, included quantity, package units, minimum charge

$0.005 USDC per call · Business, finance and compliance · POST /api/v1/metered-price · Id metered-price

Prices a usage quantity against up to 50 tiers, graduated (each tier prices only its own units) or volume (the tier holding the whole quantity prices all of it), for an agent checking a usage bill or quoting a plan. Order of operations: subtract the included quantity, convert to billing packages (per N units, rounded up, down or not at all), price the tiers, add flat fees, apply the minimum charge, round once to the currency's minor unit. Tier `upTo` bounds are inclusive and strictly ascending; only the last tier may omit it. Unit prices may carry sub-cent precision. A quantity above the last bounded tier fails. Flat fees apply when a tier holds units (graduated) or is the matching tier (volume) and quantity is above zero. Does not meter usage or apply tax.

What you get

Tier boundaries are where invoices go wrong: 100, 101 and 1000 units priced exactly, with a per-tier breakdown.

Call it

Send the JSON body below to https://agents.writerslogic.com/api/v1/metered-price. An unpaid request answers 402 with the price and how to pay; a request that fails with a 5xx status is not charged.

curl -i -X POST https://agents.writerslogic.com/api/v1/metered-price \
  -H 'content-type: application/json' \
  -d '{"quantity":"250","mode":"graduated","tiers":[{"upTo":"100","unitPrice":"0.10"},{"upTo":"1000","unitPrice":"0.08"},{"unitPrice":"0.05"}],"currency":"USD"}'

Input

FieldTypeRequiredDescription
quantitystring; length 0..30yesDecimal string such as "-12.50" (up to 15 integer and 12 fraction digits). JSON numbers are not accepted: they are binary floats.
modestring; one of "graduated", "volume"yes
tiersarray<object>; max 50 itemsyes
includedstring; length 0..30noFree quantity subtracted before packaging and tiers (never below zero).
perstring; length 0..30noUnits per billing package (default 1). Tiers are expressed in packages.
packageRoundingstring; one of "up", "down", "none"noHow a partial package is billed when per > 1. Default up.
minimumstring; length 0..30noMinimum charge in major units, applied after the tiers.
currencystringnoISO 4217 alphabetic code, upper case.
exponentinteger; 0..8no
roundingstring; one of "half-up", "half-down", "half-even", "up", "down", "ceiling", "floor"noFinal rounding to the minor unit. Default half-up. half-up: ties away from zero. half-down: ties toward zero. half-even: ties to the even neighbour. up: away from zero. down: toward zero. ceiling: toward +infinity. floor: toward -infinity.

Example request body

{
  "quantity": "250",
  "mode": "graduated",
  "tiers": [
    {
      "upTo": "100",
      "unitPrice": "0.10"
    },
    {
      "upTo": "1000",
      "unitPrice": "0.08"
    },
    {
      "unitPrice": "0.05"
    }
  ],
  "currency": "USD"
}

Result

The response is { "data": ..., "_provenance": ... }. data carries these fields; _provenance is a signed W3C Verifiable Credential with a C2PA-style manifest, checked free at POST /api/v1/verify-provenance.

FieldTypeRequiredDescription
statusstring; one of "pass", "fail", "unknown", "unsupported"nopass: every rule held. fail: a rule was violated (see witnesses). unknown: the input lacks the evidence to decide. unsupported: outside what this engine covers. Missing evidence is never a pass.
chargestringnoFinal charge at the currency's precision.
chargeMinorintegerno
exponentintegerno
billableUnitsstringnoBilling units after included quantity and packaging.
breakdownarray<object>no
unroundedTotalstringno
minimumAppliedbooleanno
witnessesarray<object>no
versionsobjectnoEvery semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile).
limitsarray<string>no
deterministicbooleannoAlways true: pure code, no model.

Pay and connect

Available through: x402 (USDC on Base), MCP. MCP clients reach it through the money-math-kit package.

Machine-readable