Cost analytics
GET /v1/analytics/cost is the single place to read cost out of MarginFront with a full breakdown attached. Use it when you need to answer:
- Which agents cost the most to run?
- Which customers are driving the cost?
- What is our cost trend day over day?
- How did this window compare to the window before it?
usageCost, whether or not the customer has a paid plan. Useful for Cost-Tracking-mode organizations that are not billing yet.
This is a read-only endpoint.
The endpoint
Method and URL:x-api-key header.
Query parameters
| Param | Type | Required | Description |
|---|---|---|---|
startDate | ISO date | yes | Start of the window (inclusive). Example: 2026-04-01. |
endDate | ISO date | yes | End of the window (inclusive). |
customerId | UUID | no | Narrow to one customer. |
subscriptionId | UUID | no | Narrow to one subscription. |
agentId | UUID | no | Narrow to one agent. |
signalId | UUID | no | Narrow to one signal. |
includePriorWindow | boolean | no | When true, the response also includes a prior field with the same shape for the prior span. |
How the prior window works
If you passincludePriorWindow=true, the API computes a second window of the same length immediately before your primary window, and runs the same aggregation on it. You get both shapes back in one call. That is how you build period-over-period trend widgets without a second round-trip.
One extra database query is used when this flag is set. Omit it when you do not need the trend.
Example curl calls
Org-wide cost for April 2026:byDay):
What you get back (200 OK)
includePriorWindow=true is set, a prior field appears at the top level with the same shape (minus its own prior):
Understanding the response
costis the total cost for the window: the sum ofusageCostacross every event that fell inside.eventCountcounts every event in the window, including events whoseusageCostis blank.eventCountWithNullCostis the subset whose cost could not be computed. They are ineventCountbut contribute0tocost. Treat this as a “needs attention” indicator.byAgent/byCustomer/bySignal/byPlanare one row per entity, with cost and event count for that entity in the window.bySignalcan include a row wheresignalIdisnull. Those are events whose signal could not be attributed.byPlancan include a row whereplanIdisnull. Those are orphan events: events with no subscription, or whose subscription was deleted. They still contribute to cost.byDayis one row per UTC day that had activity.dateis UTC midnight. Use this to chart daily trends.byModelis one row per LLM model name, pulled from the event’s payload.model: nullcovers non-LLM events and LLM events where the model field was missing.priorappears only when you passincludePriorWindow=true. Same shape as the primary window, same length of time, immediately before the primary window.
number, not strings.
When to use this vs. other endpoints
Use this endpoint when you want cost broken down by something: which agent, which customer, which signal, which day, which plan, which model. Use/v1/analytics/revenue when you also need revenue, margin, and pricing-strategy attribution.
Use /v1/analytics/usage when you want event counts and quantity totals without pricing math.
Using the Node SDK
Common errors
400 Bad Request:startDateorendDateis missing, in the wrong format, or a UUID filter is invalid.401 Unauthorized: API key missing or wrong.

