Skip to main content
POST
Create a meter

Authorizations

x-api-key
string
header
required

API key for authentication. You can find your API key in the Creem dashboard under Settings > API Keys.

Headers

Idempotency-Key
string

Deprecated: send an external_id, which makes a retry an update of the meter the first call created. Without an external_id, a retry with the same key returns the originally created meter instead of creating a duplicate; reusing a key with a different body returns the first result, and a key lasts 24 hours. After a failed create whose outcome is unclear, the key answers 429 for up to 5 minutes. With an external_id the header is ignored.

If-None-Match
string

Send * to create only: when a meter of the store already has the external_id, the call answers 412 (precondition_failed) and writes nothing. Only * is accepted on a request with an external_id (any other value answers 400); without one the header is ignored.

Query Parameters

dry_run
boolean

Send true to preview the write: the request runs as it would and is rolled back, so nothing is written and Idempotency-Key is neither read nor stored. The answer is the one the real call would give: the same status (201 for a create) and errors, and the meter with write_result.dry_run true. The id of a meter a dry run would create is never stored: a GET of it answers 404. false or no parameter is a real call; any other value answers 400.

Body

application/json
name
string

Human-readable meter name, unique within your store. Required when creating a meter. On an existing meter (by external_id) a different name renames it.

Example:

"Image generations"

event_name
string

The usage event name this meter consumes. Required when creating a meter. It cannot change after create: on an existing meter (by external_id) a different value is ignored and reported as a field_not_writable warning.

Example:

"image.generated"

aggregation
enum<string>

Aggregation applied to the matching events. Required when creating a meter. Part of the meter definition: on an existing meter (by external_id) a different value is accepted only while the meter is not locked.

Available options:
count,
sum,
average,
min,
max,
unique
Example:

"sum"

aggregation_property
string | null

Event property the aggregation reduces. Required for every aggregation except "count", which ignores it. On an existing meter (by external_id), omit it to leave it unchanged or send null to clear it.

Example:

"tokens"

filter
object

Optional filter narrowing which events the meter counts. Omitted means "count every event with this event name" on a create, and leaves the filter unchanged on an existing meter (by external_id), where a sent filter replaces the whole filter and null is rejected (400), as on update.

unit_label
string

Display unit for the metered quantity. Also names the customer-credits bucket the meter settles into. Required when creating a meter. It cannot change after create: on an existing meter (by external_id) a different value is ignored and reported as a field_not_writable warning.

Example:

"images"

external_id
string

Your own key for this meter. Creem never sets it. Unique per store, case-sensitive; 1 to 255 characters: letters, digits, _, -, . and :. With a key the call is an upsert: it creates the meter when no meter of your store has the key, and otherwise updates the meter that has it (archived meters too, which stay archived). Send If-None-Match: * to create only.

Example:

"image-generations"

Response

Only with an external_id: a meter of the store already had the key, and it was updated (write_result.result updated) or already matched the request (unchanged).

id
string
required

Meter ID

Example:

"mtr_abc123"

store_id
string
required

Store ID

Example:

"sto_abc123"

name
string
required

Meter name

Example:

"Image generations"

event_name
string
required

Usage event name the meter consumes

Example:

"image.generated"

aggregation
enum<string>
required

Aggregation applied to matching events

Available options:
count,
sum,
average,
min,
max,
unique
Example:

"sum"

aggregation_property
string | null
required

Property the aggregation reduces; null for "count"

Example:

"tokens"

filter
object
required

The meter filter; always present (empty clauses = match all)

unit_label
string
required

Display unit

Example:

"images"

status
enum<string>
required

Whether the meter is active or archived

Available options:
active,
archived
Example:

"active"

external_id
string | null
required

Your own key for this meter (external_id), unique per store. null when the meter has none.

Example:

"image-generations"

locked
boolean
required

Whether the meter is locked. A meter locks once it has processed usage or has an associated purchase; an update that changes a locked meter's definition is refused with 409. A lock freezes the filter and aggregation. event_name and unit_label can't be changed on any meter; name and external_id stay changeable. Aggregation runs asynchronously, so a meter can lock between a read that says false and the next update.

Example:

false

created_at
string
required

Creation timestamp (ISO 8601)

updated_at
string
required

Last update timestamp (ISO 8601)

write_result
object
required

What this write did and should tell you.