Skip to content
keypal
Get started
Esc
↑↓navigate↵open⌘Jpreview
KEYPAL.DocsGet started

Readme

API keys that live inside your app. Issue them, check them on every request, scope them, and revoke them everywhere at once. One dependency, typed end to end, with only key hashes stored in the database you already run.

npm install keypal
Works with
Next.jsHonoExpressElysiaFastifyBunDenoNode.jsRedisPostgreSQLMySQLMariaDBSQLiteDrizzleKyselyPrisma

Features

01

Hashed at rest.

SHA-256 or SHA-512, an optional salt, and timing-safe comparison.

sk_live_9fK2…→a3f9e1…
02

One call per request.

Reads Bearer or x-api-key and tells you exactly why a key failed.

REVOKEDEXPIREDDISABLED
03

Scopes and resources.

Global scopes, per-resource scopes, and broad scopes that imply narrow ones.

readwriteproject:42
04

Instant revocation.

verify reads the stored key every time. Revoked on one server, rejected on all.

activerevokedexpired
05

Rotation.

A new key with the same settings. The old one stops working at once.

rotate(id)→new key
06

Expiry that fails closed.

Keys stop working at the date you set. An unreadable date counts as expired.

expiresAt: 2027-01-01
07

Usage tracking.

lastUsedAt, written at most once a minute so busy keys stay cheap.

2m ago3d agonever
08

Audit logs.

Who created, rotated, disabled or revoked each key, queryable later.

12:04 revoked key_8f2
09

Bring your own table.

Already store keys? Pass findByHash and verify returns your rows, typed.

{ findByHash }

Everything below is the real API. Nothing to configure in a dashboard.

keys.ts
import { createKeys } from "keypal";
import { RedisStore } from "keypal/redis";

export const keys = createKeys({
  prefix: "sk_live_",
  storage: new RedisStore({ client: redis }),
});

const { key, record } = await keys.create({
  ownerId: "org_42",
  name: "Production server",
  scopes: ["read", "write"],
  expiresAt: "2027-01-01T00:00:00Z",
});

The secret comes back once. keypal saves only its hash, with the owner, scopes and expiry you set.

Storage adaptersCompare all →

The core has no database dependencies. Each adapter has its own import path, and its client is an optional peer you already have installed.

Open source

keypal is MIT licensed and built in the open. Read the code, file an issue, or send a pull request; the contributing guide covers running every database test locally.

izadoesdevpedroscostamax-programming

Ship API keys you'd trust in production, this afternoon.

3.3k / week★ 209 starsMIT licensed1 dependency