Need to calculate loan payments in your application? This guide covers everything you need to know about loan calculations via API, including monthly payments, amortization schedules, and implementation examples in multiple languages.
What is a Loan Calculator?
A loan calculator helps determine monthly payments, total interest, and amortization schedules for loans. It's an essential tool for mortgages, car loans, personal loans, and any financing scenario where regular payments are made over time.
Understanding loan calculations helps borrowers make informed decisions and developers build powerful financial applications.
The Loan Payment Formula
The standard loan payment formula (for fixed-rate loans) is:
M = P × [r(1+r)^n] / [(1+r)^n - 1]
Where:
M = Monthly payment
P = Principal (loan amount)
r = Monthly interest rate (annual rate / 12)
n = Total number of payments (months)
Total Interest = (M × n) - P
Amortization
An amortization schedule breaks down each payment into principal and interest portions. Early payments are mostly interest, while later payments are mostly principal.
Using the Loan Calculator API
TinyFn provides a comprehensive endpoint for loan calculations:
GET https://api.tinyfn.io/v1/math/loan
Headers: X-API-Key: your-api-key
{
"principal": 200000,
"annual_rate": 0.06,
"term_months": 360,
"monthly_payment": 1199.10,
"total_payment": 431676.38,
"total_interest": 231676.38
}
Parameters
| Parameter | Type | Description |
|---|---|---|
principal |
number | Loan amount |
annual_rate |
number | Annual interest rate (e.g., 0.06 for 6%) |
term_months |
integer | Loan term in months |
include_schedule |
boolean | Include amortization schedule (default: false) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/math/loan?principal=200000&annual_rate=0.06&term_months=360',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(data.monthly_payment); // 1199.10
console.log(data.total_interest); // 231676.38
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/math/loan',
params={
'principal': 200000,
'annual_rate': 0.06,
'term_months': 360
},
headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(data['monthly_payment']) # 1199.10
cURL
curl "https://api.tinyfn.io/v1/math/loan?principal=200000&annual_rate=0.06&term_months=360" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Mortgage Calculators: Help homebuyers understand monthly costs
- Auto Loan Tools: Calculate car financing payments
- Personal Loan Apps: Display loan options and comparisons
- Financial Planning: Project debt payoff timelines
- Lending Platforms: Generate payment schedules for borrowers
Best Practices
- Show total cost: Display both monthly payment and total interest
- Offer comparisons: Let users compare different loan terms
- Include fees: Consider additional fees like origination costs
- Round appropriately: Use proper financial rounding rules
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-math": {
"url": "https://api.tinyfn.io/mcp/math/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all math tools available via MCP in our Math MCP Tools for AI Agents guide.
Try the Loan Calculator API
Get your free API key and start calculating loan payments in seconds.
Get Free API Key