Customers can read their results and invite candidates from their own systems through a small JSON API. The interesting part was not the endpoints, it was deciding what a key is allowed to be, and what we are willing to store.
The reference is public if you want to follow along: the API docs.
A key is 240 bits, shown once
A key looks like cpa_ followed by 40 characters from 30 random bytes:
export function generateApiKey() { const key = `${API_KEY_PREFIX}${randomBytes(30).toString('base64url')}`; return { key, prefix: key.slice(0, VISIBLE_LENGTH), hash: hashApiKey(key) }; } The owner sees the full key once, when it is created. We store only its SHA-256 hash, plus the first twelve characters in the clear so a person can recognise a key in the list. A copy of the database is therefore no use for calling the API.
A plain SHA-256 is fine here, and a slow password hash would be wrong. These are 240-bit random values, not human-chosen secrets, so there is nothing to brute force, and the lookup happens on every request.
Shape checks before the database
The Authorization: Bearer header is parsed with one regex, and the token must match ^cpa_[A-Za-z0-9_-]{40}$ before we hash anything or touch the database. Garbage never reaches a query.
Two access levels, and a write key can read
Keys are either read or write. The check is one line:
export function accessAllows(granted, needed) { return granted === 'write' || needed === 'read'; } One route deserves a mention: looking up a person's invite returns their assessment link, so it needs a key that can invite, even though it is a GET. A read key that could list those links could open assessments.
Rate limits count keys and clients separately
Everything behind the API goes through one wrapper that counts a global per-client limit and a per-route limit at the same moment, to save a round trip, and refuses the request if either says no. The customer API adds its own counters: a per-key budget, a tighter one for the invite endpoint, and a fail-closed bucket for keys we do not recognise.
That last one is the one I would copy. An unknown key presenting itself repeatedly is a guessing attempt, so if the limiter's store is down, that bucket rejects rather than allows.
Errors that can be quoted
Every response carries an X-Request-ID, and API errors use one shape, { error: { code, message } }. A customer can paste the request id into a support message and we can find the line in our logs.
Revoking is immediate
Revoking a key stops it working at once, because every request checks the stored hash rather than trusting a token's claims. There is no expiry to wait out.
What to try
You do not need an account to read how it behaves. The developers page has the endpoints, the example response and the limits, and the security page explains how we treat customer data on the other side of those calls.