Attribute a total's change to quantity, price, FX, added and removed lines (sums exactly)

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

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

FieldTypeRequiredDescription
beforearray<object>; max 300 itemsyes
afterarray<object>; max 300 itemsyes
fxobjectnoMultiplier from line currency to reporting currency, before and after. Default 1 and 1.
orderarray<string; one of "quantity", "price", "fx">; max 3 itemsnoSubstitution order of the factors; each at most once. Default [quantity, price, fx].
currencystringnoISO 4217 alphabetic code, upper case.
exponentinteger; 0..8no
roundingstring; one of "half-up", "half-down", "half-even", "up", "down", "ceiling", "floor"noDefault 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.
statedBeforeTotalstring; length 0..30noOptional stated total of `before` (reporting currency) to verify.
statedAfterTotalstring; length 0..30noOptional 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.

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.
orderarray<string>no
beforeMinorintegerno
afterMinorintegerno
deltaMinorintegernoThe 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.
byFactorobjectnoSigned minor-unit effects; they sum to deltaMinor.
byLinearray<object>no
exponentintegerno
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