---
title: Tags
description: Label keys so you can find and act on groups of them.
---

Tags are labels you attach to keys, such as `'production'` or `'ci'`. They don't affect `verify` or scope checks; they exist so you can find keys later.

## Add tags

```ts
const { key, record } = await keys.create({
  ownerId: 'user_123',
  scopes: ['deploy'],
  tags: ['CI', 'production'],
})

record.tags // ['ci', 'production']
```

keypal stores tags lowercase, and lookups ignore case, so `'CI'` and `'ci'` are the same tag.

## Find keys by tag

```ts
await keys.findByTag('production')                        // every key tagged production
await keys.findByTag('production', 'user_123')            // only that owner's
await keys.findByTags(['production', 'staging'])          // keys with either tag
await keys.findByTags(['production', 'staging'], 'user_123')
```

`findByTags` returns keys that have any of the tags, not all of them. Results include revoked and disabled keys; filter on `revokedAt` or use `getKeyStatus` if you only want usable ones.

Without an owner, the lookup covers every owner's keys. Pass the owner when the request comes from a user, so one customer can't see another's keys.

## Act on a group

There is no bulk method per tag. Find the keys, then act on each:

```ts
const ciKeys = await keys.findByTag('ci', 'user_123')

for (const ciKey of ciKeys.filter((k) => !k.revokedAt)) {
  await keys.revoke(ciKey.id)
}
```

Skip keys that are already revoked, since `revoke` throws `ALREADY_REVOKED` for them. To revoke all of an owner's keys regardless of tag, use `keys.revokeAll(ownerId)`.

## Change tags

Rotating a key copies its tags; pass `tags` to replace them: `keys.rotate(record.id, { tags: ['staging'] })`. To retag without a new secret, call `update(id, { tags })` on your storage adapter.
