Skip to content

Daily and period unit economics for one business metric

GET
/api/v1/unit-economics/daily
curl --request GET \
--url 'https://example.com/api/v1/unit-economics/daily?metric=example'

Merges exact daily BilledCost with one imported business metric. A day is covered only when both a cost total (of any sign) and a positive quantity exist. Period cost and quantity aggregate covered days only. unitCost is derived in Go as cost / quantity rounded to scale 18, round-half-away-from-zero, then rendered as a decimal string with trailing zeros trimmed. A rendered “0” means the exact quotient rounds to zero at scale 18. Ratios are derived on read and never stored.

metric
required
string

Exact imported business metric name.

start
string format: date

Inclusive first UTC calendar day; defaults to unbounded.

end
string format: date

Inclusive last UTC calendar day; defaults to unbounded.

currency
string
/^[A-Z]{3}$/

Optional three-letter uppercase billing currency whose costs to merge with the business metric. Omit to use the alphabetically-first currency in the range.

Daily gaps and covered-only period unit economics.

Media typeapplication/json
object
metric
required
string
currency
required

Cost-side BillingCurrency: the currency query parameter when provided, otherwise the alphabetically-first currency in the range, or “” when the range is empty.

string
currencies
required

All billing currencies with cost rows in the requested range, sorted ascending. This is the source for a currency selector and is [] (never null) when the range is empty.

Array<string>
days
required

Union of cost and metric days, day-ascending.

Array<object>
object
date
required
string format: date
cost

Exact daily cost when a cost bin exists; any sign is retained.

string
quantity

Exact daily business quantity when a metric bin exists.

string
unitCost

Present only for a covered day. cost / quantity rounded to scale 18 with round-half-away-from-zero, trailing zeros trimmed. “0” is a meaningful rounded result and is not omitted.

string
period
required
object
coveredDays
required

Number of days carrying both cost and positive quantity.

integer
cost
required

Exact cost sum over covered days only.

string
quantity
required

Exact quantity sum over covered days only.

string
unitCost

Covered-period cost / quantity at scale 18, round-half-away-from-zero; absent when coveredDays is zero.

string
Example
{
"metric": "requests served",
"currency": "USD",
"currencies": [
"EUR",
"USD"
]
}

Missing or empty metric, an invalid start/end date, or an invalid currency shape.

Media typetext/plain
string

The named business metric has never been imported.

Media typetext/plain
string

A cost or business-metric store query failed.

Media typetext/plain
string