{"id":"invoice-audit","title":"Invoice arithmetic audit: line extensions, discounts, supplied tax, totals, with the drift in minor units","description":"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.","roi":"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.","audience":"business","package":"money-math-kit","channels":["x402","mcp"],"endpoint":{"method":"POST","url":"https://agents.writerslogic.com/api/v1/invoice-audit","path":"/api/v1/invoice-audit","contentType":"application/json"},"price":{"amount":"0.005","currency":"USDC","network":"base","perCall":true,"failedCallsCharged":false},"inputSchema":{"type":"object","additionalProperties":false,"required":["lines"],"properties":{"lines":{"type":"array","minItems":1,"maxItems":500,"items":{"type":"object","required":["quantity","unitPrice","amount"],"properties":{"id":{"type":"string","maxLength":80},"quantity":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Decimal string such as \"-12.50\" (up to 15 integer and 12 fraction digits). JSON numbers are not accepted: they are binary floats."},"unitPrice":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Price per unit in major units; sub-cent precision allowed."},"amount":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Stated net line amount after the line discount."},"discount":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Line discount as a positive amount in major units."},"taxRate":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Tax rate in percent, e.g. \"7.5\". With taxAmount it is checked. A non-zero rate without taxAmount cannot be checked: the result is unknown, and no tax is inferred."},"taxAmount":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Tax on this line as supplied."}},"additionalProperties":false}},"stated":{"type":"object","properties":{"subtotal":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Decimal string such as \"-12.50\" (up to 15 integer and 12 fraction digits). JSON numbers are not accepted: they are binary floats."},"discountTotal":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Sum of line discounts."},"taxTotal":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Decimal string such as \"-12.50\" (up to 15 integer and 12 fraction digits). JSON numbers are not accepted: they are binary floats."},"total":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Grand total; checked against subtotal + taxTotal."}},"additionalProperties":false},"currency":{"type":"string","pattern":"^[A-Z]{3}$","description":"ISO 4217 alphabetic code, upper case."},"exponent":{"type":"integer","minimum":0,"maximum":8},"rounding":{"type":"string","enum":["half-up","half-down","half-even","up","down","ceiling","floor"],"description":"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":{"type":"string","enum":["line","invoice"],"description":"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":{"type":"integer","minimum":0,"maximum":1000,"description":"Largest absolute drift in minor units still treated as a match. Default 0."}}},"resultSchema":{"type":"object","properties":{"status":{"type":"string","enum":["pass","fail","unknown","unsupported"],"description":"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":{"type":"array","items":{"type":"object","properties":{"path":{"type":"string"},"rule":{"type":"string"},"expectedMinor":{"type":"integer"},"actualMinor":{"type":"integer"},"driftMinor":{"type":"integer","description":"actual minus expected."}},"description":"Integers are exact below 10^15 minor units; a mismatch beyond that is reported only as a minor-out-of-range witness carrying exact decimal strings."}},"checksRun":{"type":"array","items":{"type":"string"}},"computed":{"type":"object","properties":{"subtotal":{"type":"string"},"discountTotal":{"type":"string"},"taxTotal":{"type":"string"},"total":{"type":"string"},"exponent":{"type":"integer"}}},"netDriftMinor":{"type":"integer","description":"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":{"type":"array","items":{"type":"object","properties":{"ruleId":{"type":"string"},"detail":{"type":"string"},"path":{"type":"string","description":"JSON pointer or dotted path into the input."},"offset":{"type":"integer"},"index":{"type":"integer"},"expected":{"description":"What the rule required."},"actual":{"description":"What the input had."}}}},"versions":{"type":"object","description":"Every semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile)."},"limits":{"type":"array","items":{"type":"string"}},"deterministic":{"type":"boolean","description":"Always true: pure code, no model."}}},"outputSchema":{"type":"object","properties":{"data":{"type":"object","properties":{"status":{"type":"string","enum":["pass","fail","unknown","unsupported"],"description":"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":{"type":"array","items":{"type":"object","properties":{"path":{"type":"string"},"rule":{"type":"string"},"expectedMinor":{"type":"integer"},"actualMinor":{"type":"integer"},"driftMinor":{"type":"integer","description":"actual minus expected."}},"description":"Integers are exact below 10^15 minor units; a mismatch beyond that is reported only as a minor-out-of-range witness carrying exact decimal strings."}},"checksRun":{"type":"array","items":{"type":"string"}},"computed":{"type":"object","properties":{"subtotal":{"type":"string"},"discountTotal":{"type":"string"},"taxTotal":{"type":"string"},"total":{"type":"string"},"exponent":{"type":"integer"}}},"netDriftMinor":{"type":"integer","description":"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":{"type":"array","items":{"type":"object","properties":{"ruleId":{"type":"string"},"detail":{"type":"string"},"path":{"type":"string","description":"JSON pointer or dotted path into the input."},"offset":{"type":"integer"},"index":{"type":"integer"},"expected":{"description":"What the rule required."},"actual":{"description":"What the input had."}}}},"versions":{"type":"object","description":"Every semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile)."},"limits":{"type":"array","items":{"type":"string"}},"deterministic":{"type":"boolean","description":"Always true: pure code, no model."}}},"_provenance":{"type":"object","description":"C2PA-aligned manifest and W3C VC 2.0 (eddsa-jcs-2022) issued by the hub DID; verify at POST /api/v1/verify-provenance"}},"required":["data","_provenance"]},"example":{"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"}},"openapiOperation":{"operationId":"invoice_audit","summary":"Invoice arithmetic audit: line extensions, discounts, supplied tax, totals, with the drift in minor units","description":"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.\n\nPrice: 0.005 USDC on Base (x402).","x-x402-price-usdc":"0.005","x-x402-amount":"5000","x-payment-info":{"protocols":["x402"],"price":{"mode":"fixed","currency":"USD","amount":"0.005"}},"x-audience":"business","x-sample-url":"https://agents.writerslogic.com/api/v1/samples/invoice-audit","security":[{"x402":[]},{"apiKey":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":false,"required":["lines"],"properties":{"lines":{"type":"array","minItems":1,"maxItems":500,"items":{"type":"object","required":["quantity","unitPrice","amount"],"properties":{"id":{"type":"string","maxLength":80},"quantity":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Decimal string such as \"-12.50\" (up to 15 integer and 12 fraction digits). JSON numbers are not accepted: they are binary floats."},"unitPrice":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Price per unit in major units; sub-cent precision allowed."},"amount":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Stated net line amount after the line discount."},"discount":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Line discount as a positive amount in major units."},"taxRate":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Tax rate in percent, e.g. \"7.5\". With taxAmount it is checked. A non-zero rate without taxAmount cannot be checked: the result is unknown, and no tax is inferred."},"taxAmount":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Tax on this line as supplied."}},"additionalProperties":false}},"stated":{"type":"object","properties":{"subtotal":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Decimal string such as \"-12.50\" (up to 15 integer and 12 fraction digits). JSON numbers are not accepted: they are binary floats."},"discountTotal":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Sum of line discounts."},"taxTotal":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Decimal string such as \"-12.50\" (up to 15 integer and 12 fraction digits). JSON numbers are not accepted: they are binary floats."},"total":{"type":"string","pattern":"^-?\\d{1,15}(\\.\\d{1,12})?$","maxLength":30,"description":"Grand total; checked against subtotal + taxTotal."}},"additionalProperties":false},"currency":{"type":"string","pattern":"^[A-Z]{3}$","description":"ISO 4217 alphabetic code, upper case."},"exponent":{"type":"integer","minimum":0,"maximum":8},"rounding":{"type":"string","enum":["half-up","half-down","half-even","up","down","ceiling","floor"],"description":"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":{"type":"string","enum":["line","invoice"],"description":"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":{"type":"integer","minimum":0,"maximum":1000,"description":"Largest absolute drift in minor units still treated as a match. Default 0."}}},"example":{"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"}}}}},"responses":{"200":{"description":"Paid result with provenance","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"status":{"type":"string","enum":["pass","fail","unknown","unsupported"],"description":"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":{"type":"array","items":{"type":"object","properties":{"path":{"type":"string"},"rule":{"type":"string"},"expectedMinor":{"type":"integer"},"actualMinor":{"type":"integer"},"driftMinor":{"type":"integer","description":"actual minus expected."}},"description":"Integers are exact below 10^15 minor units; a mismatch beyond that is reported only as a minor-out-of-range witness carrying exact decimal strings."}},"checksRun":{"type":"array","items":{"type":"string"}},"computed":{"type":"object","properties":{"subtotal":{"type":"string"},"discountTotal":{"type":"string"},"taxTotal":{"type":"string"},"total":{"type":"string"},"exponent":{"type":"integer"}}},"netDriftMinor":{"type":"integer","description":"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":{"type":"array","items":{"type":"object","properties":{"ruleId":{"type":"string"},"detail":{"type":"string"},"path":{"type":"string","description":"JSON pointer or dotted path into the input."},"offset":{"type":"integer"},"index":{"type":"integer"},"expected":{"description":"What the rule required."},"actual":{"description":"What the input had."}}}},"versions":{"type":"object","description":"Every semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile)."},"limits":{"type":"array","items":{"type":"string"}},"deterministic":{"type":"boolean","description":"Always true: pure code, no model."}}},"_provenance":{"type":"object","description":"C2PA-aligned manifest and W3C VC 2.0 (eddsa-jcs-2022) issued by the hub DID; verify at POST /api/v1/verify-provenance"}},"required":["data","_provenance"]}}}},"400":{"description":"Invalid request (no payment consumed)","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"code":{"type":"string"}}}}}},"401":{"description":"Invalid X-API-KEY","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"code":{"type":"string"}}}}}},"402":{"description":"Payment required or invalid","content":{"application/json":{"schema":{"type":"object","description":"x402 v2 PaymentRequired (also base64 in the PAYMENT-REQUIRED header)","properties":{"x402Version":{"type":"integer"},"error":{"type":"string"},"code":{"type":"string"},"resource":{"type":"object"},"accepts":{"type":"array","items":{"type":"object"}},"extensions":{"type":"object"}}}}}},"502":{"description":"Upstream failure; the payment is released or not settled","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"code":{"type":"string"}}}}}}}},"links":{"docs":"https://agents.writerslogic.com/docs/invoice-audit/","docsJson":"https://agents.writerslogic.com/docs/invoice-audit.json","sample":"https://agents.writerslogic.com/api/v1/samples/invoice-audit","openapi":"https://agents.writerslogic.com/openapi.json","catalog":"https://agents.writerslogic.com/api/v1/catalog","verifyProvenance":"https://agents.writerslogic.com/api/v1/verify-provenance","index":"https://agents.writerslogic.com/docs/index.json"}}