UsefulKey

Open‑source, Self‑hostable, Typescript toolkit for API keys and rate limiting. Designed to be simple to adopt and easy to extend.

Adapters

Use Postgres, Redis, SQLite, Cloudflare D1/KV, or HTTP backends.

Learn more →

Plugins

Enable scopes, IP access control, usage caps, and more.

Learn more →

Rate limiting

Global and token bucket strategies with persistent stores.

Learn more →

Examples

Next.js, Hono, and service‑to‑service usage patterns.

Learn more →

What is UsefulKey?

UsefulKey provides the building blocks for managing API access in your apps and services. It comes with storage adapters, middleware-friendly helpers, and pluggable features so you can choose only what you need.

  • Issue and verify API keys with optional expiration and metadata.
  • Apply global or token bucket rate limits backed by persistent stores.
  • Enable scopes, usage caps, and IP access control via plugins.
  • Use your preferred backend: Postgres, Redis, SQLite, Cloudflare, or HTTP.

Quick Example

Swap in any adapter (Postgres, Redis, SQLite, Cloudflare) when you’re ready.

import { usefulkey, MemoryKeyStore, MemoryRateLimitStore, ConsoleAnalytics } from "usefulkey";// in your server code (e.g. Next.js Route Handler, Hono, etc.)const uk = usefulkey({  keyPrefix: "uk",  adapters: {    keyStore: new MemoryKeyStore(),    rateLimitStore: new MemoryRateLimitStore(),    analytics: new ConsoleAnalytics(),  },});const create = await uk.createKey({  metadata: {    plan: "pro",  },});// app/api/protected/route.tsexport async function GET(req: Request) {  const key = req.headers.get("x-api-key") ?? "";  const verify = await uk.verifyKey({ key });  if (!verify.result?.valid) return new Response("unauthorized", { status: 401 });  return new Response("ok");}