:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
export interface AgentSpendDay {
day: string
cost_usd: number
}
export interface AgentSpendTotals {
todayUsd: number
monthUsd: number
windowUsd: number
}
export function agentSpendTotals(days: AgentSpendDay[], todayIso: string): AgentSpendTotals {
const monthPrefix = todayIso.slice(0, 7)
return days.reduce<AgentSpendTotals>(
(totals, { day, cost_usd }) => {
const dayIso = day.slice(0, 10)
return {
todayUsd: totals.todayUsd + (dayIso === todayIso ? cost_usd : 0),
monthUsd: totals.monthUsd + (dayIso.startsWith(monthPrefix) ? cost_usd : 0),
windowUsd: totals.windowUsd + cost_usd,
}
},
{ todayUsd: 0, monthUsd: 0, windowUsd: 0 }
)
}