Invoice arithmetic audit: line extensions, discounts, supplied tax, totals, with the drift in minor units

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

Recomputes up to 500 invoice lines in exact decimal arithmetic and compares them with the stated amounts, for an agent about to approve, pay or reconcile an invoice. Checks: quantity x unit price less discount equals the line amount; tax is taken as supplied (tax amounts are summed, never looked up) and, where a rate is given, tax equals rate x line amount under the declared rounding scope (per line, or per rate on the invoice); subtotal, discount total, tax total and grand total equal the sums. Each mismatch names the JSON path, the rule, the expected and actual minor units and the signed drift. Does not decide tax rates or jurisdictions, does not check vendor identity or purchase-order terms, and totals not stated are not checked.

What you get

Invoices with a one-cent rounding drift or a mis-summed total pass a human glance. Every line and total recomputed exactly, drift reported in cents.

Call it

Send the JSON body below to https://agents.writerslogic.com/api/v1/invoice-audit. 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/invoice-audit \
  -H 'content-type: application/json' \
  -d '{"currency":"USD","lines":[{"id":"A","quantity":"3","unitPrice":"19.99","amount":"59.97","taxRate":"8","taxAmount":"4.80"},{"id":"B","quantity":"2","unitPrice":"5.005","amount":"10.01","taxRate":"8","taxAmount":"0.80"}],"stated":{"subtotal":"69.98","taxTotal":"5.60","total":"75.58"}}'

Input

FieldTypeRequiredDescription
linesarray<object>; max 500 itemsyes
statedobjectno
currencystringnoISO 4217 alphabetic code, upper case.
exponentinteger; 0..8no
roundingstring; one of "half-up", "half-down", "half-even", "up", "down", "ceiling", "floor"noDefault 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.
taxRoundingstring; one of "line", "invoice"noline (default): each line's tax is rounded on its own. invoice: tax is rounded once per distinct rate on the sum of the line amounts, and compared with the supplied tax sum for that rate.
toleranceMinorinteger; 0..1000noLargest absolute drift in minor units still treated as a match. Default 0.

Example request body

{
  "currency": "USD",
  "lines": [
    {
      "id": "A",
      "quantity": "3",
      "unitPrice": "19.99",
      "amount": "59.97",
      "taxRate": "8",
      "taxAmount": "4.80"
    },
    {
      "id": "B",
      "quantity": "2",
      "unitPrice": "5.005",
      "amount": "10.01",
      "taxRate": "8",
      "taxAmount": "0.80"
    }
  ],
  "stated": {
    "subtotal": "69.98",
    "taxTotal": "5.60",
    "total": "75.58"
  }
}

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.
mismatchesarray<object>no
checksRunarray<string>no
computedobjectno
netDriftMinorintegernoSum of signed drifts over all mismatches; absent when the sum is beyond 10^15 minor units (a minor-out-of-range witness carries it as a string).
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