Skip to content

Personal finance · Calculation

Monthly budget allocation

Group entered monthly amounts into needs, wants and savings, then compare their shares with a 50/30/20 budget and calculate the unallocated balance.

Example result · byCategory.needs: 3000 See output

Cost per success
1 calculation credit
Production plans
Standard, Business, Scale, Enterprise
Plan allowances
Free sandbox
Not available

Integration example

Make a request

Use a production key scoped to monthly-budget-plan.

Keep the key on your server. A successful call uses 1 calculation credit.

Production request

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/monthly-budget-plan";
const input = {
  "monthlyIncome": 6000,
  "items": [
    {
      "amount": 3000,
      "category": "needs"
    },
    {
      "amount": 1800,
      "category": "wants"
    },
    {
      "amount": 1200,
      "category": "savings"
    }
  ]
};
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 HT_PRODUCTION_KEY on your server. Run in a POSIX shell with cURL 7.76+ and Python 3.7+ to create a request ID.

(
  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/monthly-budget-plan' \
    --header "Authorization: Bearer $HT_PRODUCTION_KEY" \
    --header 'Content-Type: application/json' \
    --header "Idempotency-Key: $request_id" \
    --data-binary @- <<'HT_INPUT'
{
  "monthlyIncome": 6000,
  "items": [
    {
      "amount": 3000,
      "category": "needs"
    },
    {
      "amount": 1800,
      "category": "wants"
    },
    {
      "amount": 1200,
      "category": "savings"
    }
  ]
}
HT_INPUT
)
If your request fails
400 INVALID_INPUT

Read error.details when present. Node prints each issue. cURL returns the JSON body. Each path points 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.

401 or 403
Check that the server has the bearer key for the endpoint’s environment and that the key includes monthly-budget-plan.
429
Read the service error code, check your allowance, and wait for the Retry-After interval when supplied before trying again.
Lost response, 409 or 503
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_ID to 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.

byCategory.needs
3000
byCategory.wants
1800
byCategory.savings
1200
Full example response (JSON)
{
  "status": "available",
  "result": {
    "byCategory": {
      "needs": 3000,
      "wants": 1800,
      "savings": 1200
    },
    "totalExpenses": 6000,
    "remaining": 0,
    "percentages": {
      "needs": 50,
      "wants": 30,
      "savings": 20
    },
    "pieData": [
      {
        "name": "Needs",
        "value": 3000
      },
      {
        "name": "Wants",
        "value": 1800
      },
      {
        "name": "Savings",
        "value": 1200
      }
    ],
    "score": 100,
    "recommendation": "on-track",
    "deviation": "aligned"
  },
  "formulaVersion": "monthly-budget-plan-htcalc-719df2c0e105",
  "units": {
    "remaining": "USD/month",
    "totalExpenses": "USD/month",
    "percentages.savings": "percent"
  },
  "assumptions": [],
  "warnings": [],
  "creditCost": 1
}

Request contract

Accepted inputs

Fields for this example. Expand the schema for all supported combinations and limits.

FieldType, units and limits

itemsRequired
array

Entered monthly budget lines.

Min items 0 · Max items 100
items[].amountRequired
number

Amount attributed to this category. In USD per month.

Min 0 · Max 10000000
items[].categoryRequired
string

Budget category.

Allowed: "needs", "wants", "savings"
monthlyIncomeRequired
number

Monthly available income. In USD per month.

Min 0.01 · Max 100000000
Example request body (JSON)
{
  "monthlyIncome": 6000,
  "items": [
    {
      "amount": 3000,
      "category": "needs"
    },
    {
      "amount": 1800,
      "category": "wants"
    },
    {
      "amount": 1200,
      "category": "savings"
    }
  ]
}
Full JSON schema
{
  "additionalProperties": false,
  "properties": {
    "items": {
      "description": "Entered monthly budget lines.",
      "items": {
        "additionalProperties": false,
        "properties": {
          "amount": {
            "description": "Amount attributed to this category. In USD per month.",
            "maximum": 10000000,
            "minimum": 0,
            "type": "number"
          },
          "category": {
            "description": "Budget category.",
            "enum": [
              "needs",
              "wants",
              "savings"
            ],
            "type": "string"
          }
        },
        "required": [
          "amount",
          "category"
        ],
        "type": "object"
      },
      "maxItems": 100,
      "minItems": 0,
      "type": "array"
    },
    "monthlyIncome": {
      "description": "Monthly available income. In USD per month.",
      "maximum": 100000000,
      "minimum": 0.01,
      "type": "number"
    }
  },
  "required": [
    "monthlyIncome",
    "items"
  ],
  "type": "object"
}

Production endpoint: POST https://calc.hasstechapi.com/v2/calc/monthly-budget-plan
Formula: monthly-budget-plan-htcalc-719df2c0e105

Related PDF reports