The data model
This page shows the objects Hardcount keeps, how they point to each other, and which ones you create. Read it once before you build an integration: every other page uses these names.
The objects form a chain. A customer subscribes to a plan. The plan’s prices name meters. Usage events fill the meters. At the end of each period, the subscription becomes an invoice, which credit and card payments settle.
The objects and the fields that link them
Section titled “The objects and the fields that link them”flowchart BT
%% Each arrow points to the object a field names. Layout only:
%% "C ~~~ PR" keeps Customer below Price, and the longer arrows
%% from Payment method and Credit ledger entry keep their labels apart.
M["Meter"]
PR["Price"]
P["Plan"]
C["Customer"]
U["Usage event"]
PM["Payment<br/>method"]
L["Credit ledger<br/>entry"]
S["Subscription"]
I["Invoice<br/>and its lines"]
D["Dunning run"]
CN["Credit note"]
PR -->|"meter_id"| M
PR -->|"plan_id"| P
C ~~~ PR
U -->|"meter_id"| M
U -->|"customer_id"| C
PM --->|"customer_id"| C
L --->|"customer_id"| C
I -->|"customer_id"| C
S -->|"customer_id"| C
S -->|"plan_id"| P
I -->|"subscription_id"| S
D -->|"invoice_id"| I
CN -->|"invoice_id"| I
Each arrow is a field on the object it starts from. For example, a usage
event carries customer_ and meter_. You send a usage event with
your own names, external_ and event_, and Hardcount
stores the IDs they point to.
One line per object
Section titled “One line per object”| Object | What it is | Who creates it | ID starts with |
|---|---|---|---|
| Customer | A person or company you bill. external_ is your own ID for it. |
You | hc_cus_ |
| Meter | A counter for one kind of usage, such as tokens. Its event_ is the name usage events send. |
You, or a recipe (a ready-made pricing setup that one API call applies) | hc_mtr_ |
| Plan | What you sell: a currency, a monthly or yearly period, an optional base fee, and prices. | You, or a recipe | hc_pln_ |
| Price | One usage rate of a plan: a meter, the labels an event must carry, and the rate. | You, or a recipe | hc_prc_ |
| Subscription | Puts a customer on one plan. A customer can have several, on plans that share no meter. | You | hc_sub_ |
| Usage event | One “this customer used this much” record, sent by your app or a LiteLLM proxy. | You | hc_evt_ |
| Invoice | A bill for one customer. Its lines say what each part costs. | Hardcount, at each period end and at a cancel. You, for a one-off invoice. | hc_inv_ |
| Credit note | A document that lowers what a customer owes on an invoice, or refunds a paid one. | You. Hardcount, for a refund made in Stripe. | hc_cn_ |
| Credit ledger entry | One change to a customer’s prepaid credit: a grant (credit added), a use, an expiry or an adjustment. | You, for grants and adjustments. Hardcount, for uses, expiries and prepaid commits (credit the customer pays for up front). | hc_ccl_ |
| Payment method | A card the customer saved through Stripe. | The customer, on a Stripe page | hc_pm_ |
| Dunning run | Hardcount retrying one unpaid invoice and emailing the customer. | Hardcount, when a charge fails or no card is saved | hc_ |
Two more objects stand apart from the chain:
- A webhook endpoint is a URL in your app that Hardcount sends events
to, such as
invoice.. You create it.paid - A provider cost is what an AI provider charges you per token, used for your margin. You create it.
What you create, and what Hardcount creates
Section titled “What you create, and what Hardcount creates”You create the setup and send the usage:
- Meters, plans and prices. One recipe call can create all three for AI tokens.
- A customer, with your
external_.id - A subscription that puts the customer on a plan.
- A top-up, when you sell the customer credit. Its payment adds the credit (Sell prepaid credit).
- Usage events, as your customers use your product.
Hardcount does the rest on its own:
- At the end of each billing period it makes the invoice and its lines.
- It uses any credit the customer holds, then charges the saved card through Stripe.
- When a charge fails, it starts a dunning run.
- It writes the credit ledger entries for credit used and credit expired.
- It sends a webhook for each step that changes an invoice, a payment, a
subscription or a dunning run. Credit used or expired sends no webhook of
its own. The
credit.webhooks are sent only when a balance crosses a threshold: it falls below your low-balance setting, reaches 0, or goes back above 0 (Credits).balance_ *
Test mode and live mode
Section titled “Test mode and live mode”Every object lives in one mode, test or live, and the two never mix. A key
that starts with hc_ sees only test objects.
Next: Usage events. More: How Hardcount works, Glossary.
Stuck, or found a bug? Ask in Discussions · Open an issue