Personal finance · Calculation
Auto loan offer comparison
Compare manually entered offers on total cost for equal loan amounts and fee-inclusive APR for different amounts. The lowest-scoring offer index is zero-based. The app component has no public page route.
The standalone offer-comparison component has no public route. This related calculator models the purchase and financing of one vehicle.
Example result · bestIndex: 1 See output
- Cost per success
- 2 calculation credits
- Production plans
- Standard, Business, Scale, Enterprise
Plan allowances - Free sandbox
- Not available
Integration example
Make a request
Use a production key scoped to auto-offer-comparison.
Keep the key on your server. A successful call uses 2 calculation credits.
Set HT_PRODUCTION_KEY on your server. Save as example.mjs and run node example.mjs with Node.js 18 or later.
import { randomUUID } from "node:crypto";
const key = process.env.HT_PRODUCTION_KEY;
if (!key) throw new Error("Set HT_PRODUCTION_KEY on your server.");
const endpoint = "https://calc.hasstechapi.com/v2/calc/auto-offer-comparison";
const input = {
"offers": [
{
"id": 1,
"lender": "Bank A",
"loanAmount": 30000,
"rate": 5.9,
"term": 60,
"fees": 0,
"feeTreatment": "financed"
},
{
"id": 2,
"lender": "Credit Union",
"loanAmount": 30000,
"rate": 4.5,
"term": 60,
"fees": 250,
"feeTreatment": "financed"
},
{
"id": 3,
"lender": "Online Lender",
"loanAmount": 30000,
"rate": 6.9,
"term": 72,
"fees": 0,
"feeTreatment": "financed"
}
]
};
const requestId = process.env.HT_REQUEST_ID || Date.now() + "." + randomUUID();
// Keep this ID to look up usage if the connection is interrupted.
console.error("Usage lookup ID:", requestId);
const response = await fetch(endpoint, {
method: "POST",
redirect: "error",
headers: {
"Authorization": "Bearer " + key,
"Content-Type": "application/json",
"Idempotency-Key": requestId
},
body: JSON.stringify(input)
});
if (!response.ok) {
const problem = await response.json().catch(() => null);
const code = problem?.error?.code || response.statusText;
const delay = response.headers.get("retry-after");
if (delay) console.error("Retry-After (seconds):", delay);
console.error("HTTP " + response.status + " " + code + ". Usage lookup ID: " + requestId);
if (Array.isArray(problem?.error?.details)) {
for (const issue of problem.error.details) console.error("Input issue:", JSON.stringify(issue));
}
process.exitCode = 1;
} else {
console.log(JSON.stringify(await response.json(), null, 2));
} cURL (shell)
(
set -eu
: "${HT_PRODUCTION_KEY:?Set HT_PRODUCTION_KEY on your server}"
request_id="${HT_REQUEST_ID:-}"
if [ -z "$request_id" ]; then
request_id=$(python3 -c 'import time, uuid; print(str(time.time_ns() // 1000000) + "." + str(uuid.uuid4()))')
fi
printf 'Usage lookup ID: %s\n' "$request_id" >&2
# On INVALID_INPUT, read error.details in the JSON response body.
curl --disable --silent --show-error --fail-with-body --include \
--request POST 'https://calc.hasstechapi.com/v2/calc/auto-offer-comparison' \
--header "Authorization: Bearer $HT_PRODUCTION_KEY" \
--header 'Content-Type: application/json' \
--header "Idempotency-Key: $request_id" \
--data-binary @- <<'HT_INPUT'
{
"offers": [
{
"id": 1,
"lender": "Bank A",
"loanAmount": 30000,
"rate": 5.9,
"term": 60,
"fees": 0,
"feeTreatment": "financed"
},
{
"id": 2,
"lender": "Credit Union",
"loanAmount": 30000,
"rate": 4.5,
"term": 60,
"fees": 250,
"feeTreatment": "financed"
},
{
"id": 3,
"lender": "Online Lender",
"loanAmount": 30000,
"rate": 6.9,
"term": 72,
"fees": 0,
"feeTreatment": "financed"
}
]
}
HT_INPUT
) If your request fails
400 INVALID_INPUT-
Read
error.detailswhen present. Node prints each issue. cURL returns the JSON body. Eachpathpoints into your request. An empty path refers to the whole body.Check the accepted inputs for required fields, units and ranges. Send the corrected JSON as a new request.
401or403- Check that the server has the bearer key for the endpoint’s environment and that the key includes
auto-offer-comparison. 429- Read the service error code, check your allowance, and wait for the
Retry-Afterinterval when supplied before trying again. - Lost response,
409or503 - Open Request lookup, select the same environment and enter the printed usage lookup ID. A settled ID has already consumed credits. To retry the same calculation, set
HT_REQUEST_IDto the original ID and reuse the same inputs. A settled request does not return its result again. Unset the variable for a new request, which can consume credits.
The usage lookup ID is the Idempotency-Key your server sends. The response’s x-request-id identifies the HTTP exchange for support.
Output
Example result
These values come from running this operation on the example inputs.
bestIndex- 1
basis- total-cost
Full example response (JSON)
{
"status": "available",
"result": {
"offers": [
{
"id": 1,
"lender": "Bank A",
"loanAmount": 30000,
"rate": 5.9,
"term": 60,
"fees": 0,
"feeTreatment": "financed",
"notePrincipal": 30000,
"payment": 578.5901086955,
"totalPayments": 34715.42,
"totalInterest": 4715.42,
"upfrontFees": 0,
"totalCost": 34715.42,
"apr": 5.900000000000751
},
{
"id": 2,
"lender": "Credit Union",
"loanAmount": 30000,
"rate": 4.5,
"term": 60,
"fees": 250,
"feeTreatment": "financed",
"notePrincipal": 30250,
"payment": 563.9513320559,
"totalPayments": 33837.1,
"totalInterest": 3587.1,
"upfrontFees": 0,
"totalCost": 33837.1,
"apr": 4.840786236621353
},
{
"id": 3,
"lender": "Online Lender",
"loanAmount": 30000,
"rate": 6.9,
"term": 72,
"fees": 0,
"feeTreatment": "financed",
"notePrincipal": 30000,
"payment": 510.0308574885,
"totalPayments": 36722.23,
"totalInterest": 6722.23,
"upfrontFees": 0,
"totalCost": 36722.23,
"apr": 6.900000000001727
}
],
"bestIndex": 1,
"basis": "total-cost"
},
"formulaVersion": "auto-offer-comparison-htcalc-719df2c0e105",
"units": {
"offers.0.payment": "USD/month",
"offers.0.totalCost": "USD",
"offers.0.apr": "percent"
},
"assumptions": [],
"warnings": [],
"creditCost": 2
}Request contract
Accepted inputs
Fields for this example. Expand the schema for all supported combinations and limits.
FieldType, units and limits
offersRequiredOffers to compare.
Min items 2 · Max items 4offers[].feeTreatmentRequiredWhether fees increase principal or are paid at signing.
Allowed: "financed", "upfront"offers[].feesRequiredEntered lender fees. In USD.
Min 0 · Max 250000offers[].idRequiredCaller-provided offer identifier.
Min 1 · Max 1000000offers[].lenderRequiredCaller-provided offer label.
Min length 1 · Max length 80offers[].loanAmountRequiredPrincipal before fees. In USD.
Min 1 · Max 250000offers[].rateRequiredAnnual note rate. In percentage points (6.5 means 6.5%).
Min 0 · Max 30offers[].termRequiredOffer term in whole months.
Allowed: 24, 36, 48, 60, 72, 84Example request body (JSON)
{
"offers": [
{
"id": 1,
"lender": "Bank A",
"loanAmount": 30000,
"rate": 5.9,
"term": 60,
"fees": 0,
"feeTreatment": "financed"
},
{
"id": 2,
"lender": "Credit Union",
"loanAmount": 30000,
"rate": 4.5,
"term": 60,
"fees": 250,
"feeTreatment": "financed"
},
{
"id": 3,
"lender": "Online Lender",
"loanAmount": 30000,
"rate": 6.9,
"term": 72,
"fees": 0,
"feeTreatment": "financed"
}
]
} Full JSON schema
{
"additionalProperties": false,
"properties": {
"offers": {
"description": "Offers to compare.",
"items": {
"additionalProperties": false,
"properties": {
"feeTreatment": {
"description": "Whether fees increase principal or are paid at signing.",
"enum": [
"financed",
"upfront"
],
"type": "string"
},
"fees": {
"description": "Entered lender fees. In USD.",
"maximum": 250000,
"minimum": 0,
"type": "number"
},
"id": {
"description": "Caller-provided offer identifier.",
"maximum": 1000000,
"minimum": 1,
"type": "integer"
},
"lender": {
"description": "Caller-provided offer label.",
"maxLength": 80,
"minLength": 1,
"type": "string"
},
"loanAmount": {
"description": "Principal before fees. In USD.",
"maximum": 250000,
"minimum": 1,
"type": "number"
},
"rate": {
"anyOf": [
{
"const": 0
},
{
"minimum": 0.000001
}
],
"description": "Annual note rate. In percentage points (6.5 means 6.5%).",
"maximum": 30,
"minimum": 0,
"type": "number"
},
"term": {
"description": "Offer term in whole months.",
"enum": [
24,
36,
48,
60,
72,
84
],
"type": "integer"
}
},
"required": [
"id",
"lender",
"loanAmount",
"rate",
"term",
"fees",
"feeTreatment"
],
"type": "object"
},
"maxItems": 4,
"minItems": 2,
"type": "array"
}
},
"required": [
"offers"
],
"type": "object"
}Production endpoint: POST https://calc.hasstechapi.com/v2/calc/auto-offer-comparison
Formula: auto-offer-comparison-htcalc-719df2c0e105