Every finance app eventually needs loan amortization. The math behind it isn't hard, but implementing it correctly — handling rounding, edge cases, irregular payments — takes longer than you'd think.
Here's how to skip all that with a single API call.
The Setup
You'll need a free API key from RapidAPI. Sign up takes 30 seconds — free tier gives you 50 calls/day.
The Code
async function getAmortizationSchedule({ principal, annualRate, termMonths }) {
const url = new URL('https://fincalcapi.p.rapidapi.com/amortize');
url.searchParams.set('principal', principal);
url.searchParams.set('annual_rate', annualRate);
url.searchParams.set('term_months', termMonths);
const response = await fetch(url, {
headers: {
'X-RapidAPI-Key': process.env.RAPIDAPI_KEY,
'X-RapidAPI-Host': 'fincalcapi.p.rapidapi.com',
},
});
if (!response.ok) throw new Error('API error: ' + response.status);
return response.json();
}
const schedule = await getAmortizationSchedule({
principal: 150000,
annualRate: 6.0,
termMonths: 180,
});
console.log('Monthly payment: $' + schedule.monthly_payment);
console.log('Total interest paid: $' + schedule.total_interest);
Why an API Instead of a Library?
A library (e.g., financial-js):
- Adds to your bundle size
- You maintain it
- Edge cases require custom code
An API:
- Zero bundle impact
- Always up-to-date
- 7 other financial calculations with the same key (NPV, IRR, mortgage, ROI, etc.)
All Available Endpoints
| Endpoint | What it calculates |
|---|---|
/amortize |
Full payment schedule |
/mortgage |
Monthly payment + total cost |
/compound-interest |
Final value with compounding |
/roi |
Simple and annualized return |
/npv |
Net present value |
/irr |
Internal rate of return |
/break-even |
Units needed to break even |
/depreciation |
Straight-line + declining balance |
Try It
Free tier: 50 calls/day — enough to build and demo any prototype.
👉 Get your API key on RapidAPI
Built with FastAPI. Hosted on Hetzner. Stateless — no data stored.
Top comments (0)