Attribute a total's change to quantity, price, FX, added and removed lines (sums exactly)
Explains why a total moved between two versions of a quote, order or invoice (up to 300 lines each), for an agent that must say how much of the change came from quantity, unit price, exchange rate, new lines and dropped lines. Lines are matched by key. Matched lines are decomposed by sequential substitution in the declared factor order (default quantity, then price, then fx), so the effects sum to the change exactly; added and removed lines are their own effects. Rounded minor-unit effects are reconciled so they sum to the rounded total change. The order matters (price-first and quantity-first attribute the cross term differently) and is echoed back. If stated totals are supplied they are checked against the recomputed totals and the drift is reported. Not a variance explanation of why a supplier changed a price.
What you get
A total up $412.07 is three different stories depending on how the cross term is booked. Exact, ordered, and summing to the cent.
Call it
Send the JSON body below to https://agents.writerslogic.com/api/v1/price-change-attribution. 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/price-change-attribution \
-H 'content-type: application/json' \
-d '{"currency":"USD","before":[{"key":"widget","quantity":"100","unitPrice":"2.00"},{"key":"gadget","quantity":"10","unitPrice":"9.99"}],"after":[{"key":"widget","quantity":"120","unitPrice":"2.10"},{"key":"gizmo","quantity":"5","unitPrice":"4.00"}],"statedBeforeTotal":"299.90","statedAfterTotal":"272.00"}'
Input
| Field | Type | Required | Description |
|---|---|---|---|
before | array<object>; max 300 items | yes | |
after | array<object>; max 300 items | yes | |
fx | object | no | Multiplier from line currency to reporting currency, before and after. Default 1 and 1. |
order | array<string; one of "quantity", "price", "fx">; max 3 items | no | Substitution order of the factors; each at most once. Default [quantity, price, fx]. |
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-even. 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. |
statedBeforeTotal | string; length 0..30 | no | Optional stated total of `before` (reporting currency) to verify. |
statedAfterTotal | string; length 0..30 | no | Optional stated total of `after` to verify. |
Example request body
{
"currency": "USD",
"before": [
{
"key": "widget",
"quantity": "100",
"unitPrice": "2.00"
},
{
"key": "gadget",
"quantity": "10",
"unitPrice": "9.99"
}
],
"after": [
{
"key": "widget",
"quantity": "120",
"unitPrice": "2.10"
},
{
"key": "gizmo",
"quantity": "5",
"unitPrice": "4.00"
}
],
"statedBeforeTotal": "299.90",
"statedAfterTotal": "272.00"
}
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. |
order | array<string> | no | |
beforeMinor | integer | no | |
afterMinor | integer | no | |
deltaMinor | integer | no | The exact change (after minus before) rounded once; equals the sum of byFactor and of byLine. It can differ by one unit from afterMinor minus beforeMinor, which round each total separately. |
byFactor | object | no | Signed minor-unit effects; they sum to deltaMinor. |
byLine | array<object> | no | |
exponent | integer | no | |
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