Skip to content
Hardcount
Run it locally
Pre-1.0 · one maintainer · Stripe and cards only · no SDKs (client libraries) yet · no production users yet. Docs describe v0.12.0 (30 Nov 2026) · What’s new →

Send a usage event

POST
/v1/usage-events
curl --request POST \
--url http://localhost:8080/v1/usage-events \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "external_customer_id": "acme-42", "event_name": "tokens", "quantity": 1200, "dimensions": { "model": "gpt-4o", "provider": "openai", "token_type": "input" }, "idempotency_key": "req-7f3a9c", "timestamp": "2026-10-12T14:03:07Z" }'

Records one usage event for a customer and a meter. You name the customer by your external_id for it and the meter by its event_name. The event counts toward the billing period its timestamp falls in, and that period’s invoice bills it.

Every event needs its own idempotency_key. Send the same key when you retry the event: an event whose key is already stored is not stored again, and the call answers 200 with the first event and an Idempotent-Replayed: true header. Retrying is safe this way; a new key on each retry bills the usage twice.

The 201 can carry a billing_status: what Hardcount found when the event arrived, such as a time that is already invoiced. The event is stored all the same.

A usage-only key (hc_ingest_…) or a secret key can call it.

Media typeapplication/json
object
external_customer_id
required

The customer’s external_id (your identifier), not the internal hc_cus_ id.

string
event_name
required

The meter’s event_name (e.g. “tokens”).

string
quantity
required

A JSON number (5) or a string holding one ("5.5", for exact decimals). At most 12 decimal places; trailing zeros do not count. Its size must be under 10^26, and it is at most 100 characters. A negative value is a correction, which a usage-only key cannot send. A missing quantity, or any other value, is refused with 422 and param: quantity.

One of:
number
dimensions

Scalar labels of the event (e.g. {“model”, “token_type”}). A price takes an event whose labels include the price’s dimension_match.

object
key
additional properties
any
idempotency_key
required

Your unique ID for this event. Pick it once, before the first send, and send the same key on every retry of the event. Keys are unique per account and mode (live or test), forever. An event whose key was already used is not stored again: the first event wins and the new body is discarded. So never reuse a key for a different event, such as a batch index or a timestamp that can repeat, or that usage is lost. Empty or whitespace-only keys are refused with 422, and so are keys longer than 255 characters. This is the only dedup key: the usage routes ignore the Idempotency-Key header.

string
<= 255 characters
timestamp

When the usage happened, as an RFC 3339 string. Leave it out to use the time Hardcount receives the event. It may be at most 5 minutes ahead of that time. Any past time is accepted, but an event in a period that is already invoiced is stored and not billed (billing_status: after_close). A value that is not an RFC 3339 string is refused with 422 and param: timestamp.

string format: date-time

Example

{
"external_customer_id": "acme-42",
"event_name": "tokens",
"quantity": 1200,
"dimensions": {
"model": "gpt-4o",
"provider": "openai",
"token_type": "input"
},
"idempotency_key": "req-7f3a9c",
"timestamp": "2026-10-12T14:03:07Z"
}

Idempotency replay — the original event is returned unchanged with an Idempotent-Replayed: true header. No duplicate row is written. The new body is not compared with the original.

Media typeapplication/json

One usage event: a quantity of one meter’s usage, for one customer, at one time. Returned by POST /v1/usage-events and POST /v1/usage-events/backfill, and listed by GET /v1/usage-events. An event counts toward the billing period its timestamp falls in.

object
id
required

The event’s ID (hc_evt_…).

string
tenant_id

The account the event belongs to.

string
customer_id
required

The customer the event was recorded for (hc_cus_…): the customer whose external_id you sent as external_customer_id.

string
meter_id
required

The meter the event counts toward (hc_mtr_…): the meter whose event_name you sent.

string
quantity
required

Exact quantity as a decimal string (e.g. “1.5”).

string
dimensions

The dimension values sent with the event. Absent when none were sent.

object
key
additional properties
any
idempotency_key

The key the event was sent with. Hardcount keeps one event per key in each account and mode (live or test), with no expiry: an event sent later with the same key is not stored again, however long after. Absent on an event stored without a key.

string
timestamp
required

When the usage happened. It decides which billing period the event counts toward. An event sent without timestamp is stamped with the time Hardcount received it. An event that is not a backfill may be at most 5 minutes ahead of that time. There is no limit on how far back it goes, but an event in a period whose invoice is already built is stored and not billed (see billing_status).

string format: date-time
origin

How the event arrived. api: POST /v1/usage-events, the batch route or the LiteLLM integration. backfill: POST /v1/usage-events/backfill, or released held usage. Absent on the rows of GET /v1/usage-events, which does not return it.

string
Allowed values: api backfill
provider_cost_cents

What serving this event cost you at your provider, in US cents as a decimal string (e.g. “0.45”), set when the event arrived: from your provider cost rates, or the cost LiteLLM reported for the call (see provider_cost_source). Absent when no rate matched or the cost was too large to store, and when the source is not_applicable.

string
provider_cost_source

Where provider_cost_cents came from: table (your provider cost rates), observed (the cost LiteLLM reported for the call), or not_applicable: the event lacks a provider or token_type dimension, or has neither model nor model_raw, so no rate can apply. Absent when the event has those dimensions but no rate matched.

string
Allowed values: table not_applicable observed
billing_status

What Hardcount found when the event arrived. It checked the event against the customer’s subscriptions, the plans and prices in force, and the invoices already built at that moment. Sent only on the answer that wrote the event; the event is stored all the same.

A status that is present was true at that moment:

  • after_close: the event’s time is already invoiced. Bill the event with a one-off invoice if it should be charged.
  • not_on_plan: a billing period not invoiced yet holds the event’s time, but its plan has no price for this meter.
  • outside_subscription: no active subscription of the customer bills the event’s time. For example, it has none, or the time is before one starts, or after one ends or its scheduled cancel.
  • no_price: the plan that bills the event’s time prices this meter, but no price of that plan takes the event’s dimensions. A price takes an event whose dimensions include all of the price’s dimension_match labels. A price’s labels are text, so a number or a true/false value in the event never matches: the number 1 does not match the string "1".

No billing_status means Hardcount found no reason then. It is not a promise that the event will be billed. Hardcount checks only the customer’s current billing periods: time after a period end whose invoice is not built yet is not checked. A later change can change the outcome either way: a subscription created or changed, a scheduled cancel undone, or a price added. The invoice is the final answer.

Two cases can make a present status wrong: a price change whose save began before a billing period started and finished after the request read the prices, and a subscription change saved while the request is in flight. Absent on a replay and on a read.

string
Allowed values: after_close no_price not_on_plan outside_subscription

Example

{
"id": "hc_evt_db6eh6qq3gpgqfoq5c3g",
"tenant_id": "hc_ten_dajqj02q3gpgqfoq5c00",
"customer_id": "hc_cus_dakhnk2q3gpgqfoq5c0g",
"meter_id": "hc_mtr_dajr122q3gpgqfoq5c10",
"quantity": "1200",
"dimensions": {
"model": "gpt-4o",
"provider": "openai",
"token_type": "input"
},
"idempotency_key": "req-7f3a9c",
"timestamp": "2026-10-12T14:03:07Z",
"origin": "api",
"provider_cost_cents": "0.3",
"provider_cost_source": "table"
}

Event ingested. A billing_status is what Hardcount found when the event arrived (see the billing_status field); the event is stored all the same.

Media typeapplication/json

One usage event: a quantity of one meter’s usage, for one customer, at one time. Returned by POST /v1/usage-events and POST /v1/usage-events/backfill, and listed by GET /v1/usage-events. An event counts toward the billing period its timestamp falls in.

object
id
required

The event’s ID (hc_evt_…).

string
tenant_id

The account the event belongs to.

string
customer_id
required

The customer the event was recorded for (hc_cus_…): the customer whose external_id you sent as external_customer_id.

string
meter_id
required

The meter the event counts toward (hc_mtr_…): the meter whose event_name you sent.

string
quantity
required

Exact quantity as a decimal string (e.g. “1.5”).

string
dimensions

The dimension values sent with the event. Absent when none were sent.

object
key
additional properties
any
idempotency_key

The key the event was sent with. Hardcount keeps one event per key in each account and mode (live or test), with no expiry: an event sent later with the same key is not stored again, however long after. Absent on an event stored without a key.

string
timestamp
required

When the usage happened. It decides which billing period the event counts toward. An event sent without timestamp is stamped with the time Hardcount received it. An event that is not a backfill may be at most 5 minutes ahead of that time. There is no limit on how far back it goes, but an event in a period whose invoice is already built is stored and not billed (see billing_status).

string format: date-time
origin

How the event arrived. api: POST /v1/usage-events, the batch route or the LiteLLM integration. backfill: POST /v1/usage-events/backfill, or released held usage. Absent on the rows of GET /v1/usage-events, which does not return it.

string
Allowed values: api backfill
provider_cost_cents

What serving this event cost you at your provider, in US cents as a decimal string (e.g. “0.45”), set when the event arrived: from your provider cost rates, or the cost LiteLLM reported for the call (see provider_cost_source). Absent when no rate matched or the cost was too large to store, and when the source is not_applicable.

string
provider_cost_source

Where provider_cost_cents came from: table (your provider cost rates), observed (the cost LiteLLM reported for the call), or not_applicable: the event lacks a provider or token_type dimension, or has neither model nor model_raw, so no rate can apply. Absent when the event has those dimensions but no rate matched.

string
Allowed values: table not_applicable observed
billing_status

What Hardcount found when the event arrived. It checked the event against the customer’s subscriptions, the plans and prices in force, and the invoices already built at that moment. Sent only on the answer that wrote the event; the event is stored all the same.

A status that is present was true at that moment:

  • after_close: the event’s time is already invoiced. Bill the event with a one-off invoice if it should be charged.
  • not_on_plan: a billing period not invoiced yet holds the event’s time, but its plan has no price for this meter.
  • outside_subscription: no active subscription of the customer bills the event’s time. For example, it has none, or the time is before one starts, or after one ends or its scheduled cancel.
  • no_price: the plan that bills the event’s time prices this meter, but no price of that plan takes the event’s dimensions. A price takes an event whose dimensions include all of the price’s dimension_match labels. A price’s labels are text, so a number or a true/false value in the event never matches: the number 1 does not match the string "1".

No billing_status means Hardcount found no reason then. It is not a promise that the event will be billed. Hardcount checks only the customer’s current billing periods: time after a period end whose invoice is not built yet is not checked. A later change can change the outcome either way: a subscription created or changed, a scheduled cancel undone, or a price added. The invoice is the final answer.

Two cases can make a present status wrong: a price change whose save began before a billing period started and finished after the request read the prices, and a subscription change saved while the request is in flight. Absent on a replay and on a read.

string
Allowed values: after_close no_price not_on_plan outside_subscription

Example

{
"id": "hc_evt_db6eh6qq3gpgqfoq5c3g",
"tenant_id": "hc_ten_dajqj02q3gpgqfoq5c00",
"customer_id": "hc_cus_dakhnk2q3gpgqfoq5c0g",
"meter_id": "hc_mtr_dajr122q3gpgqfoq5c10",
"quantity": "1200",
"dimensions": {
"model": "gpt-4o",
"provider": "openai",
"token_type": "input"
},
"idempotency_key": "req-7f3a9c",
"timestamp": "2026-10-12T14:03:07Z",
"origin": "api",
"provider_cost_cents": "0.3",
"provider_cost_source": "table"
}

The body is not one valid JSON value, it is not a JSON object, it is empty where the operation needs one, or a field has the wrong JSON type (such as a string where a number belongs). This answer is not kept for an Idempotency-Key: send the corrected request with the same key.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

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 Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter 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.

string

Example

{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "invalid JSON body",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}

No valid credential: the API key or session is missing, wrong, expired or revoked. With no API key and no valid session cookie, the message starts with missing credentials. A wrong, expired and revoked key all get the same message, invalid or expired API key.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

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 Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter 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.

string

Example

{
"error": {
"type": "authentication_error",
"code": "unauthorized",
"message": "invalid or expired API key",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}

The body is over the 1 MB limit. Send a smaller body. The answer is the same with or without an Idempotency-Key, and it is not kept for the key: the same key works for the smaller request.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

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 Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter 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.

string

Example

{
"error": {
"type": "invalid_request_error",
"code": "payload_too_large",
"message": "The request body is larger than the 1 MB limit. Send a smaller body.",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}

Validation failed and nothing was stored. param names the field: idempotency_key when it is missing, blank or longer than 255 characters, quantity when it is missing or not as described above, external_customer_id or event_name when missing or for an unknown customer or meter, timestamp for a malformed one or one more than 5 minutes ahead, dimensions for more than 16 keys or a value that is an object or an array, and properties when it has a key (it was renamed dimensions; null or {} is ignored). An unknown field is refused the same way.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

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 Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter 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.

string

Example

{
"error": {
"type": "invalid_request_error",
"code": "validation_error",
"message": "idempotency_key is required — give each event its own key and send the same key when you retry that event",
"request_id": "req_dbjg652q3gpgqfoq5cd0",
"param": "idempotency_key"
}
}

Too many requests. Wait for the number of seconds in Retry-After, then retry. The answers that pass the limit carry the X-RateLimit-* headers too.

Each API key has its own limit, by default 1,000 requests a minute (HARDCOUNT_RATE_LIMIT_GENERAL_PER_MIN), and 1,000 a second on the usage routes (HARDCOUNT_RATE_LIMIT_INGEST_PER_SEC). The dashboard sessions of one account share one limit per mode. The routes under /v1/auth and /v1/bootstrap (sign-in, password reset, invite accept, setup) count per client address, by default 100 a minute (HARDCOUNT_RATE_LIMIT_AUTH_PER_MIN). The public invoice, payment-update and cost-dashboard pages allow 60 a minute per client address.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

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 Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter 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.

string

Example

{
"error": {
"type": "rate_limit_error",
"code": "rate_limited",
"message": "too many requests — please retry after the rate limit resets",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}
Retry-After
integer
Example
12

Seconds to wait before the next request can pass, rounded up to a whole second and at least 1.

X-RateLimit-Limit
integer
Example
1000

How many requests the limit allows in its period (a minute, or a second on the usage routes).

X-RateLimit-Remaining
integer
Example
0

How many requests are left in the current period.

X-RateLimit-Reset
integer format: int64
Example
1793870460

When the whole limit is available again, as Unix seconds. One request may pass sooner; Retry-After says when.

ingest_unavailable: a customer or meter lookup, the read of the customer’s billing periods, the read of the meter’s aggregation, or the write could not be answered. Retry with the same key after Retry-After (1 second): the event is recorded once.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

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 Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter 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.

string

Example

{
"error": {
"type": "api_error",
"code": "ingest_unavailable",
"message": "usage store temporarily unavailable — retry the request with the same idempotency keys; each event is recorded once",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}

Stuck, or found a bug? Ask in Discussions · Open an issue