# keypal

> API key authentication for TypeScript. Issue keys, verify them on every request, scope and revoke them, storing only key hashes in the database you run.

## Docs

- [keypal documentation](https://keypal.dev/docs): keypal is API key authentication for TypeScript: issue keys, verify them on every request, scope and revoke them, with memory, Redis or SQL storage.

## Getting started

- [Installation](https://keypal.dev/docs/getting-started/installation): Install keypal, then add the database client for the storage adapter you use: ioredis, drizzle-orm, kysely or @prisma/client. The core needs none.
- [Quick start](https://keypal.dev/docs/getting-started/quick-start): Go from an empty project to an authenticated request in five steps: create a manager, issue a key, verify it, check its scopes, and revoke it.
- [Configuration](https://keypal.dev/docs/getting-started/configuration): Every option createKeys takes, with its default and when to change it, plus the settings you must never change once keys have been issued.

## Concepts

- [API keys](https://keypal.dev/docs/concepts/api-keys): What a keypal API key is, what gets stored instead of the secret, what verify checks on every request, and how a key moves from created to revoked.
- [Scopes and permissions](https://keypal.dev/docs/concepts/scopes-and-permissions): Limit what each API key may do with scopes, check them on every request, and let a broad scope keep granting the narrower ones you split out of it.
- [Resource scopes](https://keypal.dev/docs/concepts/resource-scopes): Grant an API key scopes on specific projects, sites or teams instead of everything, and how keypal combines global, resource and implied scopes.
- [Expiration](https://keypal.dev/docs/concepts/expiration): Give API keys an expiry date so they stop working on their own, how keypal treats dates it can't read, and how to check a key's status yourself.
- [Tags](https://keypal.dev/docs/concepts/tags): Label API keys with tags so you can find and list groups of keys, such as every key for one environment or integration, then act on each key.
- [Caching](https://keypal.dev/docs/concepts/caching): What keypal's key cache stores, why verify still reads every key from storage, and the one setup where turning the cache on saves a round trip.
- [Audit logging](https://keypal.dev/docs/concepts/audit-logging): Record who created, revoked, rotated, enabled or disabled each API key, which storage adapters keep the log, and how to query or prune the history.

## Storage

- [Overview](https://keypal.dev/docs/storage/overview): Where keypal keeps your API keys: compare the Redis, Drizzle, Kysely, Prisma and memory adapters, what each needs installed, and how to choose.
- [Memory](https://keypal.dev/docs/storage/memory): keypal's default in-process store, which keeps keys in memory for tests and local development and loses them when the process exits.
- [Redis](https://keypal.dev/docs/storage/redis): Store API keys in Redis with ioredis: the key layout keypal uses, how revoked keys expire, why updates can't undo a revoke, and what isn't supported.
- [Drizzle](https://keypal.dev/docs/storage/drizzle): Store API keys in PostgreSQL, MySQL, MariaDB or SQLite through Drizzle ORM: the table schema, column mapping, audit logs and how updates stay safe.
- [Kysely](https://keypal.dev/docs/storage/kysely): Store API keys in PostgreSQL, MySQL, MariaDB or SQLite through Kysely: the SQL for each database, column mapping, options and audit log tables.
- [Prisma](https://keypal.dev/docs/storage/prisma): Store API keys in PostgreSQL through Prisma: the model to add to your schema, field mapping, the audit log model, and how concurrent updates are handled.
- [Custom storage](https://keypal.dev/docs/storage/custom-storage): Verify API keys against a table you already have with a small findByHash lookup, or implement keypal's full Storage interface for any database.

## API reference

- [createKeys()](https://keypal.dev/docs/api-reference/create-keys): Create a keypal manager with createKeys: every option it accepts, its default, and the errors it throws for a bad length, alphabet or storage setup.
- [Verification](https://keypal.dev/docs/api-reference/verification): Verify an API key from a string or request headers with keypal, read the error code when it fails, and control how often lastUsedAt is written.
- [Key management](https://keypal.dev/docs/api-reference/key-management): Create, find, list, revoke, rotate, enable and disable API keys with the keypal manager, including what each method returns and throws.
- [Permissions](https://keypal.dev/docs/api-reference/permissions): Check a key's scopes with hasScope, hasAnyScope and hasAllScopes, including per-resource scopes, implied scopes and the checkResource helpers.
- [Audit logs](https://keypal.dev/docs/api-reference/audit-logs): Query, count, delete and summarize keypal's audit log entries, with the filters each method takes and the errors it throws when logging is off.
- [Utilities](https://keypal.dev/docs/api-reference/utilities): Manager helpers for pulling a key out of request headers, generating and hashing keys, comparing them safely, and clearing a cached key.

## Utilities

- [Standalone functions](https://keypal.dev/docs/utilities/standalone-functions): keypal functions you can call without a manager: generate and hash keys, compare them, read keys from headers, check scopes, and get key status.
- [ResourceBuilder](https://keypal.dev/docs/utilities/resource-builder): Build a key's resources map with ResourceBuilder's chainable API instead of writing nested objects by hand, then pass it to create or rotate.
- [Error handling](https://keypal.dev/docs/utilities/error-handling): Every error code keypal returns from verify or throws from manager methods, what each one means, and how to turn them into HTTP responses.

## Community

- [Contributing](https://keypal.dev/docs/community/contributing): Set up the keypal repository, run the unit tests and the Redis and Postgres suites locally, and send a pull request that keeps every key working.
- [AI resources](https://keypal.dev/docs/community/ai): Give coding agents keypal's docs: llms.txt and llms-full.txt, a Markdown copy of every page, an agent skill, and a prompt to paste into your editor.

## Changelog

- [v0.2.0](https://keypal.dev/docs/changelog/v0-2-0): Flatten ApiKeyRecord, unify scope API, fix types, move convex to optionalDependencies

## RSS Feeds

- [keypal — Changelog](https://keypal.dev/changelog/rss.xml)

## Agent resources

- [llms-full.txt](https://keypal.dev/llms-full.txt): The full Markdown of every page in one file.
- [Page Markdown](https://keypal.dev/index.md): Append `.md` to any page URL to fetch that page as raw Markdown.
- [JSON API](https://keypal.dev/api/docs/pages.json): Page index of the JSON docs API; each entry links the page's JSON and Markdown forms. Described by the OpenAPI document at https://keypal.dev/openapi.json.
- [Agent skills](https://keypal.dev/.well-known/agent-skills/index.json): Agent Skills discovery index of the skills this site publishes.
- [API catalog](https://keypal.dev/.well-known/api-catalog): RFC 9727 linkset of the APIs documented here.
- [AI catalog](https://keypal.dev/.well-known/ai-catalog.json): ARD manifest of the agent-facing resources on this site (MCP server, skills, APIs).
- [agent-readability.json](https://keypal.dev/agent-readability.json): Manifest of every agent-facing artifact on this site.
- [Sitemap](https://keypal.dev/sitemap.xml): Every indexable page URL with its last-modified date.
