Settings reference
This page lists every environment variable Hardcount and its commands read, with what each one does and what happens when it is unset.
The code is the source: internal/, internal/, internal/, cmd/ and the other cmd/ programs. A test, internal/, fails when the code reads a setting this page does not list.
How to read the Default column. “Unset:” is followed by what Hardcount does without the setting. “Stops start-up” means the program logs the reason and exits. Values are trimmed, so spaces around a value do not matter. APP_ENV decides which checks run: “production” below means APP_, and “outside local” means any value except local.
Which program reads what. Every setting below is read by the server, hardcount (also hardcount serve), unless its row names another program.
| Program | Reads |
|---|---|
hardcount migrate, migrate status, migrate rollback |
DATABASE_ or the DB_HOST set, the pool settings and MIGRATION_, all in Database. migrate rollback also reads APP_ENV and runs only when it is local. |
hardcount-bootstrap (make bootstrap) |
Every setting the server checks at start-up, so the production checks apply to it too. It always applies migrations first. It also reads the three first-account settings. |
hardcount-doctor |
DATABASE_ only. Required: without it the doctor exits with status 2. It does not read the DB_HOST set. |
hardcount-bench-seed |
Every setting the server checks at start-up, plus the two BENCH_* settings in Development and tests. |
hardcount-docs-run |
No environment variables; only its command-line flags. |
Stripe has no environment variable. Each account connects its own Stripe keys in the dashboard, under Settings → Payments, and Hardcount stores them in the database.
Database
Section titled “Database”Hardcount uses two database users. The admin user runs migrations; the limited user (hardcount_) runs every request, so row-level security (RLS) keeps accounts apart. Setup: Postgres requirements.
| Setting | What it does | Default |
|---|---|---|
DATABASE_ |
Postgres URL of the admin user. Migrations and start-up checks use it. | Required, unless the DB_HOST set below is given. Without either, start-up stops. |
DB_HOST, DB_NAME, DB_USER, DB_ |
The admin connection given in parts instead of DATABASE_. When any of the four is set, all four are required and DATABASE_ is ignored. |
Unset. Setting only some of them stops start-up. |
DB_PORT |
Port for the DB_HOST set. |
5432 |
DB_ |
Postgres sslmode for the DB_HOST set. |
require |
APP_ |
Postgres URL of the limited user that requests run as. Used exactly as written. If it is set and cannot connect, start-up stops. | Local: built from DATABASE_ with user and password hardcount_; if that fails, the server runs on the admin connection with a warning and RLS is not enforced. Outside local: required. Start-up also stops if its password is empty, is hardcount_ or equals the user name, or if the user can bypass RLS. |
DB_ |
Most open connections in each pool. The server opens two: the admin pool, used only while it starts (the schema check, and migrations when RUN_ is on), and the limited pool, which serves requests and background work. So a running copy holds up to this many. |
20. Below 1 logs a warning. |
DB_ |
Most idle connections kept in each pool. | 5. Above DB_ logs a warning. |
DB_ |
Minutes before a connection is closed and replaced. | 30 |
DB_ |
Seconds an idle connection is kept. | 120 |
DB_ |
Seconds the start-up connection check waits for Postgres. | 5 |
DB_ |
Milliseconds one account lookup may run: reading the account’s name for a team invite email or invite page. Other queries have no limit of their own: a request’s queries stop when the request’s time limit ends, 30 seconds for most routes. For a limit on every query, see Timeouts on the limited user. | 5000. Below 100 logs a warning. |
RUN_ |
Apply new migrations when the server starts. Accepts true, false, yes, no, 1, 0. |
false: then run hardcount migrate first, because the server refuses to start while a migration is missing. Any other value stops start-up. |
MIGRATION_ |
How long one migration waits for a table lock before it stops. A Go duration such as 30s, or 0 for no limit. Read by hardcount migrate, hardcount-bootstrap, and the server when RUN_ is on. |
5s. Any other value stops the migration. |
Every whole-number setting above stops start-up when its value is not a whole number, such as 5s.
Hardcount reads DATABASE_ and APP_ the way psql does. In the user name and password, percent-encode each special character, such as @ as %40 and / as %2F. When the user name or password holds an unencoded @, Hardcount refuses to start, and the error names the setting. When a parameter such as sslmode appears twice, the last value counts. DB_ needs no encoding: Hardcount encodes it.
Server and network
Section titled “Server and network”| Setting | What it does | Default |
|---|---|---|
APP_ENV |
local, staging or production. Outside local: responses carry HSTS, APP_ is required, HARDCOUNT_ needs 16 characters, and SHUTDOWN_ defaults to 5s. In staging and production the sign-in cookie is also Secure, so sign-in needs HTTPS. Production adds the checks marked “production” on this page. In local, background billing runs every 5 minutes instead of every hour. |
local. A value that starts with prod but is not production, such as prod, stops start-up. Any other unknown value logs a warning and runs as not local and not production. |
PORT |
The HTTP port the server listens on. | 8080. A value that is not a port number logs a warning. |
TRUST_ |
Addresses of your proxy or load balancer: IPs or CIDRs, comma-separated, or none for no proxy. Hardcount then takes the client address from their X-Forwarded-For. It does not read X-Real-IP. Why it matters. |
Unset: the direct peer is the client, with a warning. Production: required. An entry that is not an IP or CIDR stops start-up in every environment. |
CORS_ |
Browser origins allowed to call the API, comma-separated. Each is a scheme and a host with an optional port, such as https://, with no path, query or trailing /. A listed origin may send the sign-in cookie. * alone allows any site, without the cookie. |
http://, in every environment. A value with no origin in it (only spaces or commas), an entry that is not an origin or has a * inside it, or * beside other origins stops start-up. |
HARDCOUNT_ |
The Domain of the sign-in cookie, such as . when the API and dashboard are on sibling subdomains. |
Unset: the cookie is for the API’s host only. |
HARDCOUNT_ |
The public address of the API, so a copied cost-dashboard link is a full address. | Unset: the link is a path, and start-up logs a warning. A set value that is not a full http:// or https:// address with a host stops start-up. |
REDIS_ |
Redis, used for rate limiting only. | Production: required, and an unreachable Redis stops start-up. Elsewhere: unset logs nothing, and unreachable logs a warning. Either way rate limits are then off, except sign-in’s, which each copy counts on its own. |
HARDCOUNT_ |
API and dashboard requests a minute for each API key, or for each account’s dashboard users together in each mode (test or live). One dashboard page sends about 10 requests. | 1000. A value that is not a whole number of 1 or more stops start-up. |
HARDCOUNT_ |
Requests a minute from each client address to sign-in, password reset, invites (/) and POST /. It slows password guessing. |
100. A value that is not a whole number of 1 or more stops start-up. |
HARDCOUNT_ |
Requests a second to the usage routes (/ and /), for each API key. A request counts once, whatever it holds: one event, a batch of up to 1,000 events, or one LiteLLM send. |
1000. A value that is not a whole number of 1 or more stops start-up. |
SHUTDOWN_ |
On shutdown, how long a copy keeps serving after / turns to 503, so a load balancer stops sending it traffic first. A Go duration. See High availability. |
Outside local: 5s. Local: 0. A value that does not parse, or is negative, stops start-up. |
Public addresses (DASHBOARD_, CUSTOMER_, HOSTED_, PAYMENT_, PAYMENT_, HARDCOUNT_): in staging and production, one that starts with http:// logs a warning, because the sign-in cookie there needs HTTPS.
If Redis goes down after start-up in production, API and dashboard requests answer 429 until it is back. Usage keeps being accepted, and each copy counts sign-ins on its own. More: Redis going down after boot.
Why TRUST_PROXY matters
Section titled “Why TRUST_PROXY matters”Without it, every request behind a load balancer appears to come from the load balancer. All users then share one rate limit, the audit log shows the load balancer’s address, and 5 wrong passwords for an email, from anyone, make every new browser wait to sign in with it.
To check it, sign in, switch the dashboard to test mode and open the audit log. Sign-in entries are kept in the test-mode audit log. The newest login entry shows the address Hardcount saw. It should be yours, not the load balancer’s.
Security and keys
Section titled “Security and keys”| Setting | What it does | Default |
|---|---|---|
HARDCOUNT_ |
Encrypts stored personal data, webhook signing secrets, Stripe keys and hosted-invoice tokens (AES-256-GCM). The sign-in throttle also uses it, to hash the emails and addresses it counts. 64 hex characters: openssl rand -hex 32. Keep a copy: Back up Hardcount. |
Unset: that data is stored in plain text, with a warning. Production: required. A set value that is not 64 hex characters stops start-up in every environment. |
HARDCOUNT_ |
Allows the POST / call that creates the first account. |
Unset: that call is turned off. Outside local, a value shorter than 16 characters stops start-up. |
HARDCOUNT_ |
A separate key for the email blind index, which lets Hardcount find a customer by email address, for bounce reports and for not sending to an address that bounced. 64 hex characters, not the encryption key: openssl rand -hex 32. |
Unset: bounces are not recorded against customers, and bounced addresses are still sent to. Start-up logs a warning. A value that is not 64 hex characters logs an error and works as unset. |
Without SMTP_, Hardcount sends no email: every send fails with “SMTP not configured” and the dashboard says so. Setup for each provider: Email setup.
| Setting | What it does | Default |
|---|---|---|
SMTP_ |
Your email server’s host name. | Unset: no email is sent, with a warning at start-up. |
SMTP_ |
Your email server’s port. | 587 |
SMTP_ |
starttls (port 587), implicit (port 465) or none. |
starttls. Any other value stops start-up. In production, none makes every send fail. |
SMTP_, SMTP_ |
Login for the email server. | Unset: Hardcount sends without logging in. |
SMTP_ |
The sender address on every email. | billing@hardcount. |
HOSTED_ |
Address of the hosted invoice page: the “View & pay invoice” link in emails, and where Stripe Checkout returns a customer who paid there. | Unset: emails have no invoice link, and the page shows no Pay button, with a warning. A set value that is not a full http:// or https:// address with a host stops start-up. |
PAYMENT_ |
The “add a payment method” link in emails. Hardcount adds ?token=…. |
Unset: those emails are not sent, with a warning. A set value that is not a full http:// or https:// address with a host stops start-up. |
DASHBOARD_ |
The dashboard’s address, for password-reset and team-invite links. | Unset: password-reset emails are not sent and invites are refused, with a warning. A set value that is not a full http:// or https:// address with a host stops start-up. |
POSTMARK_, POSTMARK_ |
User name and password Postmark must send with bounce reports to POST /. Postmark only. |
Unset (either one): that route answers 401 to every post, with a warning. |
Stripe and payments
Section titled “Stripe and payments”| Setting | What it does | Default |
|---|---|---|
CUSTOMER_ |
The dashboard’s address, with no path. Stripe returns a customer here after they save a card from a setup link you send or make on the customer’s page (send-setup-email, setup-session). Hardcount adds /. |
Unset: those setup links are refused with return_, with a warning. A setup-session call that sends its own return_ still works. A set value that is not a full http:// or https:// address with a host stops start-up. |
PAYMENT_ |
Where a customer lands after adding a card from the “add a payment method” email. Hardcount adds ?status=success or ?status=cancel. |
Unset: that email is not sent, and an earlier link’s page refuses to add the card, with a warning. The link keeps working once the setting is set. A set value that is not a full http:// or https:// address with a host stops start-up. |
Background jobs
Section titled “Background jobs”| Setting | What it does | Default |
|---|---|---|
INVOICE_ |
How late usage may arrive and still be billed. A period’s invoice is built this long after the period ends. A Go duration from 0 to 72h. See Invoice timing and late usage. |
1h. Any other value stops start-up. |
How often background billing runs is not a setting: every hour, or every 5 minutes with APP_.
Observability
Section titled “Observability”| Setting | What it does | Default |
|---|---|---|
LOG_ |
debug, info, warn (or warning) or error. Logs are JSON on standard output. |
info. Any other value stops start-up. |
METRICS_ |
The bearer token a scraper must send to read /. |
Unset: / is open, except in production, where it answers 401 and start-up logs a warning. |
OTEL_ |
Your OpenTelemetry collector’s OTLP/HTTP address, such as http://. Setting it turns tracing on. |
Unset: no traces are sent. |
OTEL_ |
The service name on every trace. | hardcount |
OTEL_, OTEL_ |
Which traces to keep, with the standard OpenTelemetry values. To keep 1 in 10: parentbased_ and 0.1. |
parentbased_: every trace. |
The OpenTelemetry library reads these itself, and also its other standard OTEL_* settings, such as OTEL_ and OTEL_.
First account
Section titled “First account”hardcount-bootstrap (make bootstrap) reads these once, when it creates an account on a local development database. The server does not read them. On a server, create the first account with POST / instead: step 2 of Production on one VM.
| Setting | What it does | Default |
|---|---|---|
HARDCOUNT_ |
The dashboard owner’s email: one address with a dot in the domain, such as you@example.. |
admin@hardcount. |
HARDCOUNT_ |
The owner’s password. It needs at least 12 characters, and common leaked passwords are refused. | Unset: one is generated and printed once. |
HARDCOUNT_ |
The account’s name. | Unset: the command-line arguments, or Demo Tenant without any. |
The tool runs from source. It is not in the Docker image.
Compose only
Section titled “Compose only”These are read by Docker Compose from deploy/, by docker-compose., postgres-init. or quickstart.. Hardcount itself does not read them.
| Setting | What it does | Default |
|---|---|---|
POSTGRES_ |
Password of the database admin user. Compose builds DATABASE_ from it. Keep it URL-safe: openssl rand -hex 24. |
Required: Compose will not start without it. |
HARDCOUNT_ |
Password of the limited hardcount_ user. postgres-init. creates the user with it on the first start, and Compose builds APP_ from it. Keep it URL-safe: openssl rand -hex 24. |
Required: Compose will not start without it. |
POSTGRES_, POSTGRES_ |
Database name and admin user name. | hardcount and hardcount |
HARDCOUNT_ |
The API image to run. | hardcount-api:local, built from the checkout |
HARDCOUNT_ |
The dashboard image to run. | hardcount-dashboard:local, built from the checkout |
NGINX_ |
The host port nginx listens on, for the dashboard and API. | 80 |
HARDCOUNT_ |
Read by quickstart.: the port it writes into .env as NGINX_, so nginx listens on this machine only. |
8080 |
COMPOSE_ |
Docker Compose’s own project name. quickstart. writes hardcount-quickstart, and passes the name in its .env to every Compose command. Every quick start writes that name, so quickstart. refuses while a quick start in another folder has it. |
The directory name |
How Compose differs from running the binary:
- Compose passes only the names
docker-compose.lists. A name it does not list does nothing inyml .env.DB_and theSSLMODE DB_HOSTset are not listed: the stack’s own Postgres needs neither. To pass another name, use the override file. - Some values are fixed.
PORTis8080,RUN_isMIGRATIONS_ ON_ BOOT true, andDATABASE_andURL APP_point at the in-stack Postgres. ADATABASE_ URL DATABASE_inURL .envis ignored. - Some defaults differ.
APP_ENVisproduction,REDIS_isURL redis://,redis:6379 TRUST_isPROXY 172., and16. 0. 0/ 12, 192. 168. 0. 0/ 16 SMTP_isFROM billing@example..com quickstart.setssh APP_.ENV=local - A name set in the shell wins over
.env. A value exported in the shell, or given on the command line as inNGINX_, replaces theHTTP_ PORT=8080 docker compose up -d .envline.quickstart.runs Compose without these names and without anysh COMPOSE_setting from your shell, so it uses its.envonly.
Your own changes: the override file
Section titled “Your own changes: the override file”Put your changes to the stack in deploy/, never in docker-compose.. Compose reads the override file by itself and merges it into docker-compose., and git leaves it alone. A release can change docker-compose.. Then git checkout of that release refuses to run over your edits, and the upgrade stops.
For example, to pass OTEL_ from .env (docker-compose. does not list it):
services: hardcount-api: environment: OTEL_EXPORTER_OTLP_HEADERS: ${OTEL_EXPORTER_OTLP_HEADERS:-}Then run docker compose config in deploy/.
You see: the setting under hardcount-api, in its environment. Run docker compose up -d to start the API with it.
Development and tests only
Section titled “Development and tests only”| Setting | What it does | Default |
|---|---|---|
TEST_ |
Admin URL of the integration-test database (go test -short=false). |
postgres:// |
TEST_ |
Limited-user URL of the integration-test database. | postgres:// |
TEST_ |
The hardcount_ URL the audit-table grants test connects with. |
TEST_ with user and password hardcount_ |
HARDCOUNT_ |
Event counts for a timing measurement in internal/, such as 100000,. |
Unset: that test is skipped. |
BENCH_ |
Read by hardcount-bench-seed: seed live mode (true) or test mode (false). |
true. Any other value stops it. |
BENCH_ |
Read by hardcount-bench-seed: how many customers to create. |
200. A value that is not a whole number of 1 or more stops it. |
VITE_, VITE_ |
Read when the dashboard (web-v2) is built, not by the server: the API address and the hosted invoice address. |
Unset: the dashboard’s own address. |
Some tests start a copy of themselves and pass it variables such as HARDCOUNT_. Those are internal to the test and are not settings. The load-test stub in scripts/ reads its own variables, listed in that folder.
Stuck, or found a bug? Ask in Discussions · Open an issue