/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
string
required
Start of the date range in
YYYY-MM-DD format. Inclusive.string
required
End of the date range in
YYYY-MM-DD format. Inclusive.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.string
Optional comma-separated list of department names. When provided, only anomalies from those departments are returned. Example:
Engineering,Operations.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 ofAnomaly objects sorted by amount descending — the largest outliers appear first.
number
The transaction ID from the database.
string
The transaction date in
YYYY-MM-DD format.number
The transaction amount.
string
The department that incurred the transaction.
string
The expense category of the transaction.
string
The human-readable transaction description (e.g.
"Annual cloud infrastructure migration").number
The mean expense amount for this category across all transactions in the date range. Used as the baseline for the anomaly calculation.
number
The standard deviation of expense amounts for this category across all transactions in the date range.
(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.