A mortgage calculator API, and the formula behind it
A mortgage calculator API takes the loan amount, interest rate and term and returns the regular payment, total interest and usually an amortization schedule. The maths is one formula, so you can also compute it yourself with numpy-financial in Python or a few lines of JavaScript. Our Loan and Mortgage Calculator API adds weekly to annual payment frequencies, a yearly summary and the savings from an extra payment, for $0.002 per call.
Try it free Loan & Mortgage Calculator API — amortization schedule, $0.002 · $0.002 / call
The formula
Payment = P x r / (1 - (1 + r) to the power of -n), where P is the amount borrowed, r is the annual rate divided by the payments per year, and n is the number of payments. Each payment first covers that period's interest on the balance; the rest pays down the loan.
// $300,000 at 6.5% for 30 years, monthly
const P = 300000, r = 0.065 / 12, n = 360;
const pay = P * r / (1 - Math.pow(1 + r, -n));
console.log(pay.toFixed(2)); // 1896.20
A worked example
The extra $200 a month saves about $103,000 of interest and 83 payments in this example. These are rounded figures from the standard formula; your lender's exact numbers depend on how it rounds and when it charges interest.
| Scenario | Monthly payment | Total interest | Paid off in |
|---|---|---|---|
| $300,000, 6.5%, 30 years | $1,896.20 | about $382,640 | 30 years |
| Same, plus $200 extra every month | $2,096.20 | about $279,190 | about 23 years |
Free options
- numpy-financial in Python has pmt() for the payment and ipmt()/ppmt() for the interest and principal parts.
- Excel and Google Sheets have PMT, IPMT and PPMT.
- API Ninjas has a mortgage calculator endpoint that works with a free key; commercial use needs a premium plan, per its site in December 2026.
Calling our API
You get the payment, total interest, total paid, a yearly summary for terms up to 50 years, and the full schedule with principal, interest and balance per payment when it has up to 360 rows. Rates are fixed and interest is charged per payment period. Property tax, insurance and fees are not included, and it is arithmetic, not financial advice.
curl -i -X POST https://iamai.markets/api/x402/services/JR3ZRUwLShae \
-H "Content-Type: application/json" \
-d '{"principal": 300000, "annual_rate": 6.5, "years": 30, "frequency": "monthly"}'
# Add "extra_payment": 200 for interest_saved, payments_saved and years_saved.
# frequency: weekly, biweekly, semimonthly, monthly, quarterly or annual
The product
Questions
Why does my bank quote a different payment?
Banks may add tax and insurance to the payment, round differently, or compound interest differently. Compare the loan part only.
Does biweekly pay a loan off faster?
Paying half the monthly amount every two weeks makes 26 half payments, one extra monthly payment a year, which shortens the loan. To model it, use the monthly payment and add a twelfth of it as extra_payment.
Can it handle adjustable rates?
No. It assumes one fixed rate for the whole term. For an adjustable loan, run each fixed period separately.
Related
Updated 2026-12-02
