Pre-1.0 · one maintainer · Stripe and cards only · no SDKs (client libraries) yet · no production users yet.

Usage billing for AI products, on your own servers.

Price tokens per model, sell prepaid credit, and see what each customer costs you. Hardcount makes the invoices, and Stripe charges the card.

Free and open source (MIT). Try it before you trust it: the demo runs on your computer in test mode, where no real money moves. Questions go to Sagar, the one maintainer, by email or GitHub Discussions.

What it looks like

One month of AI usage for one customer, from the demo in test mode. Its dates follow the demo’s test clock, a month ahead.

The demo invoice. One line per model and token type, priced per million tokens.
Invoice HC-000001 in the Hardcount dashboard: input, output and cache_read lines for claude-sonnet-4.5 and input and output lines for claude-haiku-4.5, priced per 1M tokens, $5.73 due.
Your margin, per model. Each model's usage revenue against what the AI provider charged you: Sonnet 67.1%, Haiku 20.0%. Only you see this.
The Margin card for the demo customer: $5.73 usage billed, $2.76 provider cost, 51.9% margin, with claude-sonnet-4.5 at 67.1% and claude-haiku-4.5 at 20.0%.

What you get

Hardcount is an open-source alternative to Stripe Billing and Lago.

  • No Stripe Billing fee. Stripe charges the card at its normal fee. Hardcount takes nothing on what you bill. Pricing →
  • Every model on one meter. Each model and token type gets its own price, on one meter. Price per model →
  • One free edition. MIT, with no paid edition: every feature is in the same code. Pricing →
  • Light to run. One Go program and Postgres, plus Redis for rate limits, on your own servers. Self-host →

Everything it does: Product →
How it compares, including where others are ahead: Compare →

Is it right for you?

A good fit if

  • You charge by usage, especially for an AI product priced per token.
  • You want billing on your own servers, with usage and invoices in your own Postgres.
  • You are comfortable running a server, Postgres and Redis yourself.

Not a fit if you need

  • Simple per-seat pricing paid by card. Stripe Billing already does that well.
  • A payment processor other than Stripe.
  • Marketplace payouts split between sellers.
  • Revenue recognition or accounting reports.
  • Quotes or multi-phase contracts for sales-led deals.
  • A customer portal. Customers pay on a hosted invoice page instead.

How it works

  1. Your app sends usage. One event for each thing you count, such as the tokens of one AI call. A LiteLLM proxy can send them for you.
  2. Hardcount prices it. It uses your plan’s prices, and at the end of each billing period it makes the invoice and its PDF.
  3. Stripe charges the card. If a charge fails, Hardcount retries on a schedule and, once email is set up, emails your customer. The subscription doesn’t switch to “past due”: your app decides when to limit access.

One usage event, sent with curl:

curl -X POST http://localhost:8080/v1/usage-events \
  -H "Authorization: Bearer $HARDCOUNT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"event_name": "tokens",
       "external_customer_id": "acme",
       "quantity": 1200,
       "dimensions": {"model": "claude-sonnet-4.5", "token_type": "input"},
       "idempotency_key": "req-42:input"}'

There are no SDKs yet. Your first invoice, step by step → does every request with curl.

Run it locally

This starts Hardcount on your computer in test mode and runs a demo. You need git and Docker 24 or newer, with Compose. On Windows, use WSL.

git clone https://github.com/gethardcount/hardcount.git
cd hardcount/deploy/compose
./quickstart.sh
./quickstart.sh demo

./quickstart.sh prints your dashboard address and sign-in, and saves them in quickstart-credentials.json. The demo then sets prices for AI tokens, sends a customer’s token usage the way LiteLLM does, moves a test clock to the end of the month, and makes the invoice, its PDF and your margin report.

The demo ends like this, with links to open in the dashboard:

━━━ Done: every step above ran and was checked ━━━

  ✓ One call loaded a price for each model and token type
  ✓ LiteLLM-shaped calls to two models became usage events, with no SDK
  ✓ Hardcount recorded what each usage event cost you
  ✓ A test clock moved one month, and Hardcount made the invoice and its PDF
  ✓ Your margin on this customer, by model

    Invoice:  http://localhost:8080/invoices/hc_inv_…
    Customer: http://localhost:8080/customers/hc_cus_…

Done? ./quickstart.sh stop keeps your data. ./quickstart.sh destroy deletes it.

The full walkthrough, and where to click: Quick start →

  • Running it for real: one VM with Docker Compose, or two or more copies behind a load balancer. Self-host →
  • What it costs: Hardcount is free; you pay for your server and Stripe’s card fee. Pricing →
  • What’s next: spend alerts and SDKs for Go and TypeScript in v0.10. Roadmap →
  • Questions? Lock-in, safety for real money, who maintains it. FAQ →

Try it on your computer

Start Hardcount in test mode and run its demo. Found something rough? Open an issue or a Discussion.