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 (user_id) and the key that made it (minted_by; None for one the owner made). secret is the key itself (nk_live_...): Key.create returns it once, and nothing shows it again.

Attributes
idstr
namestr
scopeslist[str]
spend_cap_usd_per_monthfloat | None
expires_atdatetime | None
user_idstr | None
minted_bystr | None
secretstr | None
rawdict[str, Any]

The response JSON exactly as the API sent it.

createclassmethodasync

noclick.Key.create(
    name, scopes, *, spend_cap_usd_per_month=None, expires_at=None, user_id=None,
    client=None
) -> 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 (minted_by) and never outlives it: revoking a key revokes every key it made, and theirs. user_id pins it to one of your users. Signed in, the account's owner makes any key.

Parameters
namestrrequired
scopesSequence[str]required
spend_cap_usd_per_monthfloat | Nonedefault None
expires_atdatetime | Nonedefault None
user_idstr | Nonedefault None
clientClient | None

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

(default None)
Returns
Key
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).

Usage
worker = noclick.Key.create("queue worker", ["queues", "agents"], spend_cap_usd_per_month=20)
os.environ["WORKER_KEY"] = worker.secret