# API keys and scopes

> Create keys with only the access they need, pin them to a user, and cap what they spend.

A platform **API key** lets your server act for your account. Create keys in the developer console under **API keys**. Each key has a name, the scopes it may use, and optionally a monthly spend cap, an expiry and a user it's pinned to. Creating one accepts the [Developer Terms](https://www.noclick.com/legal/developer-terms) and the [Acceptable Use Policy](https://www.noclick.com/legal/acceptable-use).

The console's Quickstart gives a coding agent a key without showing it the key: its prompt carries a one-time setup code (30 minutes), and the agent's one command trades it for a key that goes from the response straight into the project's `.env`:

```bash
curl -fsS -X POST https://api.noclick.com/v1/setup -d code=nc_setup_... >> .env
```

That key is named "Coding agent" and has the console's Full access. A code works once; a used or expired one fails with `410`. An agent with no account at all can [sign itself up](https://www.noclick.com/docs/guide/agent-access.md) and hand the account to you to claim.

A key starts with `nk_live_` and is shown once, when you create it. After that the console shows only its prefix, like `nk_live_ab12`, which is also how you filter [activity](https://www.noclick.com/docs/guide/activity.md) by key.

## Scopes

| Scope | Lets the key |
| --- | --- |
| `users` | create, read, update and suspend users, and mint sessions |
| `credentials:request` | create and delete connections, send connect links, import credentials |
| `credentials:use` | list and verify connections and run integration operations through them |
| `credentials:token` | read a connection's OAuth access token |
| `tools` | get toolkit definitions and run tool calls |
| `humans` | ask, approve and notify people |
| `approvals:answer` | [approve or decline a call NoClick holds](https://www.noclick.com/docs/guide/policy.md#answer-held-calls-from-your-code) for your account's owner's yes, as long as the key didn't make it and could make it itself; a key with `*` doesn't have it unless it's named too |
| `approvals:policy` | [switch what NoClick holds](https://www.noclick.com/docs/guide/policy.md#switch-them-for-your-account) for a person, for the whole account, or loosen them [for one key or connected app](https://www.noclick.com/docs/guide/policy.md#set-them-for-one-key-or-connected-app) (never itself; tightening one takes no scope); a loosening it makes waits a 10-minute undo window and tells the owner; a key with `*` doesn't have it unless it's named too |
| `keys:create` | [make secret keys](https://www.noclick.com/docs/guide/keys.md#let-your-code-make-keys) no wider than itself, which never outlive it; a key with `*` doesn't have it unless it's named too |
| `agents` | create, change and message agents |
| `agents:terminal` | [take over](https://www.noclick.com/docs/guide/agents.md#take-over-its-terminal) a coding agent's terminal, which shows its sandbox's keys and tokens; a key with `*` doesn't have it unless it's named too |
| `account:phones` | [link phone numbers](https://www.noclick.com/docs/guide/phone-numbers.md#link-your-own-phone-to-your-account) to your account and unlink them; a linked number signs in to your account, so a key with `*` doesn't have it unless it's named too |
| `workflows:variables` | [read a workflow's variables' values](https://www.noclick.com/docs/guide/workflows.md#read-its-variables-values), of a workflow you own or can edit, which no other read of it carries; they hold what its steps are given as secrets, so a key with `*` doesn't have it unless it's named too |
| `channels` | open and use channels |
| `inbox` | create and read inboxes, and reply |
| `phone` | buy phone numbers, route them and place calls |
| `ai` | call [AI models](https://www.noclick.com/docs/guide/ai.md); talking to an agent as a model takes `agents` |
| `render` | draw a picture or a PDF for a reply from a composition, kept as one of your files; a page of a repo in it takes `repos` too |
| `sandboxes` | start and use sandboxes |
| `operations` | list operations, count them, and read an agent turn's tool calls |
| `usage` | read spend and the activity logs |
| `policy` | read and set policy |
| `brand` | read and set your brand |
| `webhooks` | manage [webhook endpoints](https://www.noclick.com/docs/guide/webhooks.md) and read events |
| `webhooks:reveal` | read a webhook's signing secret; a key with `*` doesn't have it unless it's named too |
| `mcp_servers` | create and manage [hosted MCP servers](https://www.noclick.com/docs/guide/mcp-servers.md) |
| `storage` | create [buckets](https://www.noclick.com/docs/guide/storage.md), read and write their files, and mint signed links |
| `volumes` | create [volumes](https://www.noclick.com/docs/guide/volumes.md), and read and write their files |
| `dicts` | create [dicts](https://www.noclick.com/docs/guide/dicts.md), and read and write their keys |
| `queues` | create [queues](https://www.noclick.com/docs/guide/queues.md), and send, receive and settle messages |
| `secrets` | create [secrets](https://www.noclick.com/docs/guide/secrets.md) and set their values, which no key can read back |
| `workflows` | run [workflows](https://www.noclick.com/docs/guide/workflows.md) and give them endpoints |
| `apps` | create and deploy [apps](https://www.noclick.com/docs/guide/apps.md), and set their bindings, secrets, schedules and [app services](https://www.noclick.com/docs/guide/app-services.md) |
| `repos` | create [repos](https://www.noclick.com/docs/guide/repos.md), commit, and mint clone links |
| `databases` | create and query [databases](https://www.noclick.com/docs/guide/databases.md), migrate, restore and branch them |
| `domains` | search, connect and manage [domains](https://www.noclick.com/docs/guide/domains.md) |
| `domains:buy` | buy and renew domains, which charges your account |
| `browsers` | start [browsers](https://www.noclick.com/docs/guide/browser.md) and manage browser profiles |
| `machines` | rent and run [machines](https://www.noclick.com/docs/guide/machines.md) |
| `machines:vetting` | [ask for machines](https://www.noclick.com/docs/guide/machines.md#network-and-the-usage-policy) for your company from your server, saying who accepted the machines usage policy and when; a key with `*` doesn't have it unless it's named too |

### Scopes for cards

> [!NOTE]
> Invite-only beta. These scopes come with the beta primitives they cover. [Request access](mailto:support@noclick.com?subject=Invite-only%20beta%20access).

| Scope | Lets the key |
| --- | --- |
| `cards` | create and manage [cards](https://www.noclick.com/docs/guide/cards.md) and read their transactions |
| `cards:reveal` | hand out a card's number: a [reveal](https://www.noclick.com/docs/guide/cards.md#show-a-number-to-a-person) page or a purchase's number |

The console offers sets of these: **Full access** is every scope except the five that read secrets, `credentials:token`, `cards:reveal`, `webhooks:reveal`, `agents:terminal` and `workflows:variables`, `approvals:answer`, which says yes for your account's owner, `approvals:policy`, which switches what waits for them, `machines:vetting`, which accepts the machines usage policy for your company, `keys:create`, which makes keys, and `account:phones`, which links a phone that signs in to your account (each of those it offers on its own, beside Full access); `GET /v1/account` lists what a key with `*` holds in `meta.scopes`, and the scopes a key holds only when they're named in `meta.explicit_scopes`; **Read-only** is `usage` and `operations`; or pick your own. Only grant `credentials:token` to code that must call providers directly, since it can read your users' access tokens, `cards:reveal` only to code that hands a card's number to a person or announces purchases, `webhooks:reveal` only to the receiver that verifies deliveries, `agents:terminal` only to the server that opens a terminal for the person who'll drive it, `workflows:variables` only to code that must read a variable's value itself, for the workflows you own or edit, `approvals:answer` only to the code that decides on your behalf, on a key of its own, `approvals:policy` only to the code that sets your approval switches, `machines:vetting` only to the sign-up flow that records who accepted the machines usage policy, `keys:create` only to the code that hands its workers keys of their own, and `account:phones` only to the code a person links their own phone through.

A call a key's scopes don't cover fails with `noclick.PermissionDenied`. Reading, waiting on and cancelling one operation by its id needs no scope.

## Let your code make keys

One of your account's own secret keys that names `keys:create` makes keys from your server, so code that runs a fleet of workers hands each its own key without you minting them in the console:

```python
worker = noclick.Key.create("queue worker 7", ["queues", "agents"], spend_cap_usd_per_month=20)
os.environ["WORKER_KEY"] = worker.secret   # shown this once
```

```ts
import { Key } from "noclick";

const worker = await Key.create("queue worker 7", ["queues", "agents"], { spendCapUsdPerMonth: 20 });
process.env.WORKER_KEY = worker.secret!; // shown this once
```

Over HTTP it's `POST /v1/keys`. A key it makes is never wider than the key making it, and each way it would be is refused with `noclick.PermissionDenied` naming the `field`:

- **Scopes**: only scopes the key holds itself; `*` only from a key holding `*`, and a scope a key holds only when it's named (`keys:create` among them) only from one that names it.
- **Cap**: when the key has a monthly spend cap, the new key needs one too, at most that.
- **Expiry**: when the key expires, the new key does too, no later.
- **Approval settings**: the new key starts with the [approval settings](https://www.noclick.com/docs/guide/policy.md#set-them-for-one-key-or-connected-app) the key set for itself.
- **Lifetime**: the new key names the key that made it (`minted_by`), and revoking a key revokes every key it made, and theirs.

It makes secret keys only (a publishable key is yours to make, signed in), and only a key acting for your whole account makes any: a key pinned to a user, a session, an app's code, an MCP connection or an agent's turn is refused.

## Pin a key to a user

A key pinned to a user always acts for that user, without `as_user`, and can't act for any other: naming another user fails with `noclick.PermissionDenied`. Use one for a service that only ever works for one customer.

For code in a browser, don't use a pinned key: mint a [session](https://www.noclick.com/docs/guide/sessions.md), which expires.

## Cap a key's spend

A key's monthly spend cap limits everything done with that key. Once it's reached, calls with the key fail with `noclick.SpendCapExceeded` until the next month or until you raise the cap. You can change a key's name and cap at any time in the console.

## Publishable keys

A web page can't hold a secret key: anyone can read it from the page. A **publishable key** starts with `nk_pub_` and is safe to ship in a page, because it can call only the endpoints you've made public and listed on it, such as a [shared agent's chat](https://www.noclick.com/docs/guide/sharing.md#chat-from-your-own-page) or a [workflow's public endpoint](https://www.noclick.com/docs/guide/workflows.md#give-it-an-endpoint). It reads nothing else, and spends only through those endpoints.

Create one in the console under **API keys**, choosing **Publishable** as the key type. For each one you pick:

- **Endpoints**: the public endpoints it may call. A key with none calls nothing.
- **Per-visitor limit**: how many calls one visitor (by IP address) may make a minute; more fail with `429` and `noclick.RateLimited`. The default is 20.
- **Allowed origins**: the sites that may use it from a browser, like `https://acmebooking.com`. A call from any other origin, or with none, fails with `403` and `noclick.PermissionDenied`; with none listed, any site may.

A publishable key is shown in full at any time, since it isn't a secret, and it still has a monthly spend cap: the turns and runs its visitors start count against it, as well as against your other caps. Change its endpoints, limit and origins from its row's menu; calls to an endpoint you take off it, or one that stops being public (an agent whose page you turn off), are refused at once.

A visitor never learns about your account's money or rules: a call a cap, your balance or your policy stops answers `409` with `not_available`, and the reason shows in your [activity](https://www.noclick.com/docs/guide/activity.md) instead. A call for a user whose [spending you paused](https://www.noclick.com/docs/guide/spend.md#pause-a-user-s-spending) answers `402` `spending_paused` with only what you wrote for that user: its `user_message`, `action` and `since`. Any other route refuses a publishable key with `403`. To act as one of your users in the browser, with their own agents and connections, mint a [session](https://www.noclick.com/docs/guide/sessions.md) instead.

## Keys NoClick gives your apps

An app you deploy on NoClick whose repository asks for [a key to your account](https://www.noclick.com/docs/guide/apps.md#a-key-to-your-account) is given one by NoClick once you agree to what it can do. It's listed here with your other keys, naming its app (`project_id` in `GET /v1/keys`), and you cap, rename and revoke it the same way. It has no value to show: its app's production release holds a bearer of its own, starting `nk_app_`, that works only while that release serves. It never holds `*`, `keys:create`, `approvals:answer` or `approvals:policy`.

## Revoke a key

Revoking a key stops it at once, along with every session it minted. To rotate a key, create the new one, deploy it, then revoke the old one.
