---
title: keypal
sidebar:
  label: Introduction
description: API keys for TypeScript. Generate, hash, verify, scope, rotate, and revoke them, stored wherever you already keep data.
---

keypal issues API keys, stores only their hashes, and checks incoming requests against them. It reads the key from the request headers, rejects keys that are unknown, revoked, expired, or disabled, and gives you the stored record so you can check its scopes.

Keys can live in memory, Redis, or a SQL database through Drizzle, Kysely, or Prisma. If you already have an API keys table, keypal can verify against it without moving your data.

```ts
import { createKeys } from 'keypal'

const keys = createKeys({ prefix: 'sk_' })

// Issue a key. `key` is the secret: show it to the user once, then discard it.
const { key, record } = await keys.create({
  ownerId: 'user_123',
  scopes: ['read'],
})

// Check a request.
export async function handler(request: Request) {
  const result = await keys.verify(request.headers)
  if (!result.record) {
    return Response.json({ error: result.errorCode }, { status: 401 })
  }
  if (!keys.hasScope(result.record, 'read')) {
    return Response.json({ error: 'forbidden' }, { status: 403 })
  }
  return Response.json({ owner: result.record.ownerId })
}
```

## Get started

**[Installation](/docs/getting-started/installation)**

Add keypal and the client for your storage.

**[Quick start](/docs/getting-started/quick-start)**

Create a key and verify your first request.

**[Configuration](/docs/getting-started/configuration)**

Every option `createKeys` takes.

## Go deeper

**[Concepts](/docs/concepts/api-keys)**

How verification works, and what scopes, expiry, tags, caching, and audit logs do.

**[Storage](/docs/storage/overview)**

Memory, Redis, Drizzle, Kysely, Prisma, or your own.

**[API reference](/docs/api-reference/create-keys)**

Every manager method and what it returns.

**[Utilities](/docs/utilities/standalone-functions)**

Hashing, scope checks, and errors without a manager.
