Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/astrxnomo/financial-analytics-agent/llms.txt

Use this file to discover all available pages before exploring further.

The /api/finance/anomalies endpoint detects statistically unusual expense transactions using a per-category baseline. For each expense category in the date range, the endpoint computes the mean and standard deviation of all transaction amounts within that category. Any individual transaction whose amount exceeds mean + (threshold × stddev) is flagged as an anomaly. The default threshold is 2.5 standard deviations, which catches genuine outliers while filtering out normal month-to-month variation. Lowering the threshold (e.g. to 2) surfaces more anomalies; raising it (e.g. to 3 or above) restricts results to only the most extreme cases.

Request

from
string
required
Start of the date range in YYYY-MM-DD format. Inclusive.
to
string
required
End of the date range in YYYY-MM-DD format. Inclusive.
threshold
number
default:"2.5"
Standard deviation multiplier used to determine the anomaly cutoff. A transaction is flagged when its amount exceeds categoryMean + threshold × categoryStdDev. Must be between 1 and 6. Defaults to 2.5.
departments
string
Optional comma-separated list of department names. When provided, only anomalies from those departments are returned. Example: Engineering,Operations.
categories
string
Optional comma-separated list of category names. When provided, only anomalies in those categories are returned. Example: Travel,Office.
The statistical baseline (mean and standard deviation) is always computed from all transactions in the full date range, regardless of the departments or categories filters. Those filters only narrow the list of returned anomalies, not the data used to calculate the baseline. This preserves statistical validity — filtering the baseline to a single department would distort the distribution and produce different (less meaningful) σ values.

Response

The response is an array of Anomaly objects sorted by amount descending — the largest outliers appear first.
id
number
The transaction ID from the database.
date
string
The transaction date in YYYY-MM-DD format.
amount
number
The transaction amount.
department
string
The department that incurred the transaction.
category
string
The expense category of the transaction.
description
string
The human-readable transaction description (e.g. "Annual cloud infrastructure migration").
categoryMean
number
The mean expense amount for this category across all transactions in the date range. Used as the baseline for the anomaly calculation.
categoryStdDev
number
The standard deviation of expense amounts for this category across all transactions in the date range.
The deviation in standard deviations for any given anomaly is (amount - categoryMean) / categoryStdDev. The chat UI displays this as a “Nσ” label (e.g. “3.2σ above average”) using the fmtSigma formatter from app/_components/charts.ts.

Examples

All anomalies with the default threshold

curl "http://localhost:3000/api/finance/anomalies?from=2024-01-01&to=2025-12-31"

Travel and Office anomalies only

curl "http://localhost:3000/api/finance/anomalies?from=2024-01-01&to=2025-12-31&categories=Travel,Office"

Lower threshold to catch more anomalies

curl "http://localhost:3000/api/finance/anomalies?from=2024-01-01&to=2025-12-31&threshold=2"

Example response (excerpt)

[
  {
    "id": 4821,
    "date": "2024-09-14",
    "amount": 48200,
    "department": "Engineering",
    "category": "Cloud Infrastructure",
    "description": "Data transfer spike — autoscaling incident",
    "categoryMean": 11400.50,
    "categoryStdDev": 9820.30
  }
]

Error Response

{
  "error": {
    "formErrors": [],
    "fieldErrors": {
      "threshold": ["Number must be greater than or equal to 1"]
    }
  }
}

Build docs developers (and LLMs) love