Get the customer's usage and cost for a period
const url = 'http://localhost:8080/v1/customers/example/usage';const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request GET \ --url http://localhost:8080/v1/customers/example/usage \ --header 'Authorization: Bearer <token>'Usage per meter on the customer’s active and trialing
subscriptions, priced the same way the invoice prices it. With no
from and to, the period is the current billing cycle of the
subscription whose cycle started last, as of the customer’s current
time (the test clock’s time for a customer on a test clock). A
trialing subscription’s cycle starts when its trial ends, so it is
not picked before then, unless no subscription’s cycle has started.
Send both or neither.
Errors: 404 if the customer does not exist. 422 when only one of
from/to is sent, when from is not before to, when the
window is longer than one year, or (code
customer_has_no_subscription) when no period is sent and the
customer has no subscription with a current cycle.
Decimal quantities are returned as strings. If the daily series
fails to load, buckets is empty and warnings says so.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”Query Parameters
Section titled “Query Parameters”Start of the window. RFC 3339 instant or YYYY-MM-DD (start of that day, UTC).
End of the window, exclusive. RFC 3339 instant or YYYY-MM-DD (23:59:59.999999 UTC that day, so the day is included).
Responses
Section titled “Responses”Usage for the period.
object
The window the response covers. With no from and to
(current_billing_cycle), each subscription is rated over its
own current billing period, and the period runs from the
earliest start to the latest end of those periods. A meter’s
totals and daily buckets cover its own subscription’s whole
period, including usage a threshold invoice already billed.
object
current_billing_cycle: no from and to were sent, and
the amounts are what the period’s invoices bill.
explicit: the window you sent. Its amounts are an
estimate, so a past window can differ from its invoices.
Only active and trialing subscriptions are counted: the
usage of a canceled subscription is left out. Each
subscription’s usage in the window is priced at the
prices of its current billing period.
One entry per item of each active or trialing subscription. A
subscription with several plans appears once per plan, with the
same id.
object
object
Decimal string.
One row per (plan, price) that took usage, and a no_price row
per plan for the usage no price of that plan took. Two plans can
price one meter differently.
object
Absent on a no_price row.
The labels the price takes. Absent for a price that takes every event.
object
Decimal string.
Price per unit in cents, as a decimal string; the same figure the invoice line shows.
True for usage no price of the plan took. Hardcount bills nothing for it, and it is left out of the meter’s totals.
One entry per currency.
object
Problems found working out this usage, in words, such as usage that no price takes or a meter whose usage went below zero.
One entry per UTC day in the period, including days with no usage.
object
Quantity per meter ID for that day, as a decimal string.
object
Example
{ "period": { "source": "current_billing_cycle" }}Customer not found.
object
object
One of invalid_request_error, authentication_error,
rate_limit_error or api_error. Every error the API
answers has this shape, including an unknown path (404,
code route_not_found) and a method the path does not take
(405, code method_not_allowed, with an Allow header).
The few exceptions are listed in docs/api-surface.md.
The request field the error is about. Sent only when the error
names one. A request body may hold only the fields its
operation lists, spelled and cased as listed: any other
field, or one the server sets (such as id), is refused
with 422 and param naming it. An operation with no request body lists no fields: send
no body, {} or null. The Stripe and Postmark webhooks and
the LiteLLM callback take their sender’s body as it comes.
Example
{ "error": { "type": "invalid_request_error" }}Bad or missing period (param is from, to or period).
object
object
One of invalid_request_error, authentication_error,
rate_limit_error or api_error. Every error the API
answers has this shape, including an unknown path (404,
code route_not_found) and a method the path does not take
(405, code method_not_allowed, with an Allow header).
The few exceptions are listed in docs/api-surface.md.
The request field the error is about. Sent only when the error
names one. A request body may hold only the fields its
operation lists, spelled and cased as listed: any other
field, or one the server sets (such as id), is refused
with 422 and param naming it. An operation with no request body lists no fields: send
no body, {} or null. The Stripe and Postmark webhooks and
the LiteLLM callback take their sender’s body as it comes.
Example
{ "error": { "type": "invalid_request_error" }}