ADR-133: API keys are secret or ingest; platform keys and /v1/tenants are gone
Date: 2026-10-30 Status: Accepted
Summary
Section titled “Summary”Hardcount stores two API key types. A secret key (hc_) can do
everything in one account. An ingest key (hc_, “Usage only” in the
dashboard) holds one permission, usage:ingest, and can only send usage
events. The platform key type and the / routes it served are
removed: nothing could issue the first platform key, and the routes read
and created accounts across the whole server. Accounts are created only by
the bootstrap.
Context
Section titled “Context”The LiteLLM proxy held a full-access key. The LiteLLM guide told
operators to put a secret key in litellm_. A proxy config is
copied between machines, kept in a repo, and read by whoever runs the
proxy. A copy of that key could refund, void, read every customer and mint
new keys. The proxy only ever needs to send usage.
Peers ship a key or role for ingest only. From their code, read for the competitive review of 2026-10-23:
- Flexprice enforces five roles, one of them
event_(ingestor config/).rbac/ roles. json - Lago has three free roles over about 130 permissions
(
config/).permissions. yml - Kill Bill uses Apache Shiro roles and permissions.
Stripe’s restricted keys (docs) answer the same need: a key limited to what one integration does.
The platform key could not exist. CreateKey issued a platform key
only to a caller that already held one, and no route, tool or bootstrap
step made the first. / (create, list, get) answered only to a
platform key, so it served no one. It also reached across tenants: the
list read every account on the server. The pre-release reviews
(simplification audit 2026-10-23, right-thing review 2026-10-12) both
asked to cut it.
Decision
Section titled “Decision”- Key types.
api_iskeys. key_ type secretoringest(api_, migration 00221). The prefixes arekeys_ key_ type_ check hc_andsecret_ {live, test}_ hc_. The parser (ingest_ {live, test}_ auth.) reads only these, so anStoredKeyTypes hc_key is an unknown key (401).platform_ POST /takesv1/ api-keys key_type secret(the default) oringest; any other value is a 422. - One new permission.
usage:ingest(auth.) gatesPermUsageIngest POST /,v1/ usage-events POST /andv1/ usage-events/ batch POST /. Secret keys and dashboard sessions hold it along with every other permission. An ingest key holds only it.v1/ integrations/ litellm/ spend - What an ingest key reaches. The three routes above, and
GET /, which needs no permission for any credential. Every other route that takes an API key answers it with the ordinary missing-permission 403 (v1/ whoami insufficient permissions: this key type does not have <perm> access). That includes backfill, the held-usage release and discard, provider costs and the usage reads, which needusage:writeorusage:read. - Platform removed.
KeyTypePlatform,PermTenantRead,PermTenantWrite, thehc_prefix, theplatform_ /routes, their spec paths, the tenant HTTP handler andv1/ tenants tenant.andService. Create Listare deleted. Accounts are created bytenant., fromRunBootstrap POST /orv1/ bootstrap cmd/, which calls it directly and needs no HTTP route.hardcount-bootstrap - Migration 00221 refuses, never deletes. If any row has
key_, the migration stops with the count and a runbook link, and changes nothing. Such a row was written by hand, and deleting a credential is the operator’s call.type = 'platform'
Why this design
Section titled “Why this design”- A permission, not a path list. Routes already declare the permission
they need. The ingest key is a permission set with one entry, so the
usual gate refuses it, with the usual answer, on every route that names
any other permission. A new route that forgets its permission fails
TestIngestKey_, which walks the router.RefusedOnEveryRouteButUsage - Not
usage:write. That permission also backfills past usage, releases and discards held usage, and edits provider costs. A gateway needs none of those. - whoami stays open. It needs no permission today, for any key. It tells an operator which account and mode a key belongs to, which is the first check after pasting a key into a proxy. It returns no customer data.
- Remove, not hide, the platform key. A credential type that cannot be issued is dead code on the auth path, and its routes are the only ones that cross tenants. Keeping them would mean testing and documenting a surface no one can reach.
Alternatives considered
Section titled “Alternatives considered”- A. Per-resource scopes, like Stripe restricted keys: a key carries a chosen list of permissions. Rejected for now: no user has asked for any scope but ingest, and a scope picker is a larger UI and API surface. The permission strings already exist, so this can come later without a new model.
- B. Ingest key with
usage:write: no new permission. Rejected: see “Notusage:write” above. - C. Keep platform keys and add a bootstrap path that mints the first one: rejected. One server with several accounts is served by running the bootstrap again (CONTRIBUTING, “Local services”). No user has asked to manage accounts over the API.
Consequences
Section titled “Consequences”Positive
Section titled “Positive”- The LiteLLM guide gives the proxy a usage-only key. A leaked proxy config can add usage, but cannot move money, read customers or make keys.
- One fewer key type, three fewer routes, and no route that reads across tenants.
Risks / open items
Section titled “Risks / open items”- A leaked ingest key can still send usage for any customer of its account. Usage is billed, so treat it as a secret, rotate it like any key and watch the Usage page.
- An install with a hand-made platform row stops at 00221 until the row is deleted (runbook).
- Roles for dashboard users are still recorded and not enforced (ADR-081). This ADR does not change that.
Amendment 2026-11-30: the ingest key also reads the live balance
Section titled “Amendment 2026-11-30: the ingest key also reads the live balance”What: the gateway’s key reports usage, which adds to a bill, and reads a
customer’s remaining credit, GET /. It
cannot send a correction (a negative quantity), which lowers one. The live
route needs usage:ingest, which a secret key and a dashboard session hold
too, so they read it as before. An ingest key still reads no customer, no
settled balance, no grant and no ledger.
Why: the first offer’s gateway needs both: it reports usage, and it stops serving a customer whose credit is used up (Stop usage when credit runs out). The alternative was a secret key in a proxy config, the copy this ADR exists to remove.
What a leaked ingest key shows now: the live balance of a customer in
its mode whose Hardcount ID (hc_) the holder already has. The key
cannot list customers or find one by its external ID.
References
Section titled “References”- ADR-011 (dashboard sessions are separate from API keys), ADR-033 (the LiteLLM adapter), ADR-081 (no RBAC for members).
- Migration 00221 (
internal/).platform/ migrate/ sql/ 00221_ api_ key_ type_ ingest. sql internal/,auth/ permission. go internal/,api/ router. go internal/.api/ ingest_ key_ test. go - API keys, LiteLLM integration.
Stuck, or found a bug? Ask in Discussions · Open an issue