Home / API docs / Financial Math API
Math

Financial Math API

POST /api/calc/finance $0.005 per call USDC on Base · x402

Exact financial + token math. POST {op:…}: compound (growth with per-period contributions), amortize (payment, total interest, schedule), npv, irr (deterministic bisection) — and token_units: exact decimal↔base-unit conversion via BigInt for any token decimals (ETH 18, USDC 6), the 18-decimal math that float64 silently corrupts. Iterative series computed exactly, never guessed.

Parameters

NameInDescription
opbodyrequiredcompound | amortize | npv | irr | token_units
principalbody
ratebodyannual %, e.g. 6.5
yearsbody
periods_per_yearbodydefault 12
contribution_per_periodbody
cashflowsbodynpv/irr — period 0 first
amountbodytoken_units — decimal or base-unit string
decimalsbodytoken_units — ETH 18, USDC 6
tobodytoken_units — base | decimal

Example request

curl -X POST "https://api.webbersites.com/api/calc/finance" \
  -H "Content-Type: application/json" \
  -d '{"op":"amortize","principal":300000,"rate":6.5,"years":30}'
# first call returns 402 + payment requirements; an x402 client pays and retries automatically

Example response

{
    "op": "amortize",
    "payment_per_period": 1896.2,
    "periods": 360,
    "total_interest": 382633.47
}
MCP tool: post_calc_finance — via npx -y webbersites-x402-mcp (local, key stays on your machine) or the remote endpoint https://api.webbersites.com/mcp.

How payment works

There is no signup and no API key. Call the endpoint; it replies 402 Payment Required with machine-readable payment requirements. Your client signs a USDC transfer authorization (EIP-3009, gasless) and retries with the X-PAYMENT header — @x402/fetch does this automatically. See the overview for a working snippet.