Key

Keys: one of your account's own keys makes another for your code, no wider than itself.

class Key

A platform secret key of your account's: its id, name, scopes, monthly cap, expiry, the user it's pinned to (userId) and the key that made it (mintedBy; null for one the owner made). secret is the key itself (nk_live_...): Key.create returns it once, and nothing shows it again.

Attributes
idstring
namestring
scopesstring[]
spendCapUsdPerMonthnumber | null
expiresAtDate | null
userIdstring | null
mintedBystring | null
secretstring | null
rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

createstatic

static create(
  name: string,
  scopes: string[],
  options?: KeyOptions,
): Promise<Key>

Make a secret key from your server, with one of your account's own keys that names the keys:create scope (a key with every scope, *, holds it only when it's named too). The new key is no wider than the one making it: only scopes it holds itself (* only from a key holding *), a monthly cap when it has one, at most its own, an expiry when it has one, no later, and the approval settings it set for itself. It names the key that made it (mintedBy) and never outlives it: revoking a key revokes every key it made, and theirs. A key without keys:create, one acting for a user, or a key wider than the one making it rejects with PermissionDenied (its field names what). Signed in, the account's owner makes any key.

const worker = await Key.create("queue worker", ["queues", "agents"], { spendCapUsdPerMonth: 20 });
process.env.WORKER_KEY = worker.secret!;
Parameters
namestringrequired
scopesstring[]required
options.spendCapUsdPerMonthnumber

A monthly cap: required (at most its own) when the key making it has one.

options.expiresAtDate

When it expires: required (no later than its own) when the key making it expires.

options.userIdstring

Pins it to one of your users: it acts only for them.

options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns
The key, its ``secret`` shown this once: store it where your code reads it.

Raises: noclick.PermissionDenied: a key without keys:create, one acting for a user, or a key wider than the one making it (field names what: scopes, spend_cap_usd_per_month, expires_at).