Rate limits
A rate limit caps how many requests Hardcount accepts in a period. A request
over the limit gets 429 and runs nothing. This page gives each limit, the
headers that report it, and how to retry.
The limits
Section titled “The limits”These are the defaults. The person who runs your Hardcount server can change the first three (see Change a limit).
| Requests | Limit | Counted for each |
|---|---|---|
The API and the dashboard: every /v1 route not listed below |
1,000 a minute | API key. Dashboard users share one count per account and mode (test or live). |
Usage: / and / |
1,000 a second | API key, or account and mode for the dashboard |
Sign-in, password reset and invites (/), and / |
100 a minute | Client IP address |
The hosted invoice page, the payment-update page and the public cost dashboard (/) |
60 a minute | Client IP address |
POST / |
1 a minute, only on a server with Redis | Customer |
- Each API key has its own counts. A usage-only key on a gateway and a secret key on your server never use up each other’s limit.
- One key has two separate counts: one for usage routes, one for every other route.
/health,/,health/ ready /and the routes Stripe and Postmark call are not counted.metrics
The count refills steadily. It is not reset at the start of each minute. A full allowance lets a burst of up to the limit through at once. After that, one request’s allowance comes back every period ÷ limit: every 60 ms at 1,000 a minute, every second at 60 a minute.
A request with a bad key is refused before it is counted. It gets 401
(see Authentication). A key or
session cookie of the wrong shape is refused without reading the database;
a well-formed one that matches nothing costs one read. Hardcount does not
limit how many requests one address sends before they are authenticated on
the /v1 routes that take a key or session cookie, or on the Stripe and
Postmark webhooks under /,
which are checked by their signature or password. Put a per-address limit
on both in front of Hardcount, in your load balancer or proxy. The proxy in
Hardcount’s Compose stack carries one, ready to switch on
(how). Its 429 is
nginx’s own page, with no Retry-After header, not the answer below.
The headers
Section titled “The headers”Every counted response carries three headers:
| Header | Value |
|---|---|
X-RateLimit-Limit |
The limit, such as 1000 |
X-RateLimit-Remaining |
Requests you can send now |
X-RateLimit-Reset |
When your full allowance is back, in Unix seconds |
A 429 also carries Retry-After: the number of seconds until your next
request can pass, at least 1.
The 429 answer
Section titled “The 429 answer”{ "error": { "type": "rate_limit_error", "code": "rate_limited", "message": "too many requests — please retry after the rate limit resets", "request_id": "req_…" }}The setup-link email answers cooldown_ instead, with the message a setup link was sent to this customer recently — wait before sending again.
It counts every request for that customer that got past the rate limit in
the last minute, even one that then failed, for example because the
customer has no email.
Sign-in has a second, separate guard: after failed sign-ins it answers 429
with code login_. See Errors.
Retry after a 429
Section titled “Retry after a 429”- Wait the number of seconds in
Retry-After. - Send the same request again, with the same
Idempotency-Keyheader or the same usageidempotency_.key
A 429 rate_ or login_ ran nothing and stored nothing,
so the same key is safe to send again. cooldown_ is different: it
is stored under the request’s Idempotency-Key like any other answer, so
after the minute, send the request with a new key. See
Idempotency.
To stay under the limit:
- Give each integration its own API key.
- Send usage in batches:
POST /takes up to 1,000 events in one request.v1/ usage-events/ batch - Cache answers you poll, such as the live credit balance.
The two calls page shows a client that waits for
Retry-After, in four languages.
When Redis is down
Section titled “When Redis is down”Hardcount counts requests in Redis. A production server
(APP_) refuses to start without a Redis it can reach. If Redis
goes down after start-up, each limit acts differently:
| Requests | In production | Elsewhere |
|---|---|---|
The API and the dashboard, /, and the public pages |
Every request gets 429, with Retry-After: 60, until Redis is back |
Not limited |
| Usage, and the setup-link email | Not limited | Not limited |
| Sign-in, password reset and invites | Counted by each server process on its own | Counted by each server process on its own |
Without Redis, a server with several copies (replicas) lets one address sign in up to the limit on each copy. More: Redis going down after boot.
Change a limit
Section titled “Change a limit”The person who runs the server sets these, as environment variables. On the
Docker Compose stack, add them to deploy/, then run
docker compose up -d. Each must be a whole number of 1 or more; any other
value stops start-up.
| Setting | Default | Limit |
|---|---|---|
HARDCOUNT_ |
1000 |
The API and the dashboard, a minute |
HARDCOUNT_ |
1000 |
Usage, a second |
HARDCOUNT_ |
100 |
Sign-in, password reset, invites and /, a minute |
The public-page limit and the setup-link limit cannot be changed. Behind a
load balancer, set TRUST_, or every client shares the load balancer’s
address and its per-address limits. More: Settings.
Stuck, or found a bug? Ask in Discussions · Open an issue