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 →

Create a meter

POST
/v1/meters
curl --request POST \
--url http://localhost:8080/v1/meters \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: 5f0c8a2e-7b1d-4c3e-9a6f-2d8b4e1c7a90' \
--data '{ "event_name": "tokens", "name": "Tokens", "unit": "tokens", "aggregation": "sum" }'

Creates a meter. event_name is what your usage events send for it, and it cannot change later. unit defaults to unit and aggregation to sum. A meter only counts: put its prices on a plan (POST /v1/plans/{id}/prices). The create is written to the audit log.

Idempotency-Key
string
<= 255 characters

Makes the call safe to retry. Send a random UUID, and the same value on every retry. Keys are kept per account and mode, and every API key and dashboard user of the account shares them, so make a key unpredictable. A key over 255 characters is refused with 422 validation_error, param: Idempotency-Key. A request sent with a key runs to its end even if the client disconnects: retry with the same key for its answer. For 24 hours, a repeat from the same caller (the same API key or the same dashboard user) with the same key, method, path, query string and body gets the first response again, byte for byte, with an Idempotent-Replayed: true header, instead of running again. A first answer of 401, 403, 409, 422 or 503, or a 400 invalid JSON body, is not kept, so a retry with the same key runs again. A request to a path or method no route serves holds no key. A repeat sent while the first request is still running gets 409 with code conflict_idempotency at once: retry it in a moment with the same key. The same key from another caller, or with a different method, path, query string or body, is a 422 with code idempotency_error at once, even while the first request runs. The query string must match byte for byte. After 24 hours the key is free, and a request with it runs as new. The other error cases are in Idempotency. The usage routes do not take it: each usage event carries its own idempotency_key. The requests whose answer carries a secret shown only once (creating or rotating an API key, creating a webhook endpoint or rotating its signing secret, rotating a customer’s cost dashboard token, creating a card setup session) do not take it either: Hardcount does not keep that answer.

Example

5f0c8a2e-7b1d-4c3e-9a6f-2d8b4e1c7a90
Media typeapplication/json
object
event_name
required

The event_name usage events will send for this meter. Letters, digits, - and _; at most 100 characters. Unique in the account and mode.

string
name
required

The display name. Spaces at the ends are trimmed; then at most 255 bytes (UTF-8).

string
unit

The unit of the quantity, such as tokens or seconds. Empty or left out is unit.

string
default: unit
aggregation

How the meter rolls its events into one quantity per billing period. Fixed once the meter has a usage event.

string
default: sum
Allowed values: sum count max last

Example

{
"event_name": "tokens",
"name": "Tokens",
"unit": "tokens",
"aggregation": "sum"
}

The new meter, with has_usage false.

Media typeapplication/json

A meter counts one kind of usage: every usage event that sends its event_name. A meter has no price of its own. Plans price it (/v1/plans/{id}/prices). Create, list, get and update meters under /v1/meters.

object
id
required

The meter’s ID, hc_mtr_ and 20 characters.

string
tenant_id

The account the meter belongs to.

string
event_name
required

The event_name usage events send for this meter. Letters, digits, - and _, at most 100 characters. Unique in the account and mode, and fixed after create.

string
name
required

The meter’s display name, at most 255 bytes (UTF-8).

string
unit
required

The unit of the quantity, such as tokens or seconds. unit when none was given.

string
aggregation
required

How the meter rolls its events into one quantity per billing period: sum adds the quantities, count counts the events, max takes the highest quantity, and last takes the latest event’s quantity, by timestamp, then by id. Every price of the meter bills under it. Fixed once the meter has a usage event (see has_usage).

string
Allowed values: sum count max last
has_usage

Whether the meter has usage events. Once it has, its aggregation cannot change. Held usage for its event_name does not count until it is released. Returned when you create, get or update one meter; the meter list leaves it out. A create or update that succeeded leaves it out if it could not be read.

boolean
created_at
required

When the meter was created.

string format: date-time
updated_at
required

When the meter was last changed.

string format: date-time

Example

{
"id": "hc_mtr_dajr122q3gpgqfoq5c10",
"tenant_id": "hc_ten_dajqj02q3gpgqfoq5c00",
"event_name": "tokens",
"name": "Tokens",
"unit": "tokens",
"aggregation": "sum",
"has_usage": false,
"created_at": "2026-09-15T09:00:00Z",
"updated_at": "2026-09-15T09:00:00Z"
}

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 credential is valid but may not call this route. A usage-only key (hc_ingest_…) can only send usage, read a customer’s live credit balance and call GET /v1/whoami; use a secret key. The message names the permission the key lacks. A browser request that would change data (POST, PUT, PATCH or DELETE) from a page on another site gets this 403 too, with the message cross-site request blocked.

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": "forbidden",
"message": "insufficient permissions: this key type does not have customer:read access",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}

A meter with this event_name already exists in this account and mode (already_exists, param: event_name).

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": "already_exists",
"message": "a meter with event_name \"tokens\" already exists",
"request_id": "req_dbjg652q3gpgqfoq5cd0",
"param": "event_name"
}
}

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"
}
}

A field failed validation (validation_error, param names it): a missing or too long event_name or name, an event_name with other characters than letters, digits, - and _, an unknown aggregation, or an unknown field.

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": "must contain only alphanumeric characters, hyphens, and underscores",
"request_id": "req_dbjg652q3gpgqfoq5cd0",
"param": "event_name"
}
}

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.

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