Invoice arithmetic audit: line extensions, discounts, supplied tax, totals, with the drift in minor units
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
| Field | Type | Required | Description |
|---|---|---|---|
lines | array<object>; max 500 items | yes | |
stated | object | no | |
currency | string | no | ISO 4217 alphabetic code, upper case. |
exponent | integer; 0..8 | no | |
rounding | string; one of "half-up", "half-down", "half-even", "up", "down", "ceiling", "floor" | no | 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. |
taxRounding | string; one of "line", "invoice" | no | line (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. |
toleranceMinor | integer; 0..1000 | no | Largest 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.
| Field | Type | Required | Description |
|---|---|---|---|
status | string; one of "pass", "fail", "unknown", "unsupported" | no | pass: 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. |
mismatches | array<object> | no | |
checksRun | array<string> | no | |
computed | object | no | |
netDriftMinor | integer | no | Sum 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). |
witnesses | array<object> | no | |
versions | object | no | Every semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile). |
limits | array<string> | no | |
deterministic | boolean | no | Always 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
- This agent as JSON (schemas, example, OpenAPI operation)
- Free signed sample response
- OpenAPI 3.1 · Catalog · Index of every agent