# Accounts and keys

This page says who an account is, what an API key opens, and how the CLI logs in. It teaches `durable-sdk login`, `login --with-key`, `logout`, `whoami`, `keys list` and `keys revoke`, and the routes `GET /whoami`, `GET /keys`, `POST /keys`, `DELETE /keys/:id` of [the API](https://durablesdk.com/docs/reference/api.md).

## Organizations are tenants

Join with an email and a code. Your first organization is made for you and named from your address; rename it on the dashboard. A password is optional (set one on your account page; a sign-in then offers it or a code). A tenant is an organization, on the Free tier in the default [region](https://durablesdk.com/docs/hosting/regions.md); every app, key, deployment and run belongs to one organization, and the organization switcher in the dashboard's header chooses the active one. An invitation from an organization's Members page lands you on the same sign-up, titled with the organization's name.

- **Members and roles** are the organization's. An `admin` may create and delete apps, mint keys up to the `admin` scope, read and rotate the database's read string and change the organization's settings; a `member` may deploy, promote, roll back, set secrets, add domains and act in the Console tab, and mints keys up to the `deploy` scope.
- **Seats** are the organization's members. The Free tier holds three: the fourth invitation is refused at the invite. Pro is priced per seat ([pricing and tiers](https://durablesdk.com/docs/operate/pricing-and-tiers.md)).
- **The organization's slug** names nothing on a hostname (the app's slug is the hostname), so renaming an organization costs nothing.
- **Leaving**: a member removed from the organization, or demoted, loses every key they minted under it at once; a deleted user loses their keys across every organization; a deleted organization has every key revoked and every app put into the deletion hold ([the hold](https://durablesdk.com/docs/hosting.md)).

## API keys

A key is what a CI job and an agent hold. It is `dsk_live_` followed by forty characters of `[A-Za-z0-9]`; a test fixture's is `dsk_test_`. The pattern `dsk_(live|test)_[A-Za-z0-9]{40}` is published on [the security page](https://durablesdk.com/security) so a secret scanner catches a committed one.

- **Minted by a person, once.** A key is made from `/dashboard/keys` or by the CLI's browser hand-off below, with a name, one scope and an expiry (30, 90 or 365 days from the dashboard; 90 days from the hand-off). The value is shown once and never again. **A key never mints a key** (`plane.key.mint_by_person`): `POST /keys` is admitted for a signed-in person alone, so a leaked key cannot propagate. There is no `keys create` verb for the same reason.
- **At rest** the platform holds the key's SHA-256, its prefix (`dsk_live_` and the first eight characters, for the list), the tenant, the scope, the name, who minted it, when, the expiry, the last day it was used and the revocation. The presented key is looked up by its digest and compared in constant time. The value is in no ledger row, no log line and no output; the ledger rows for a mint and a revoke carry the key's id and prefix.
- **One scope, a ladder**: `read` < `deploy` < `admin`. A key's scope is at most its minter's role; `GET /whoami` says the scope of the principal in hand; a request past the scope is 403 `plane.key.scope_short`.

| Scope    | Opens                                                                                                                                                                                                         |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `read`   | every GET under the organization: apps, environments, deployments and their events, secrets' names, domains, the database's status, logs, usage, limits, status, the Console tab's reads, the platform's runs |
| `deploy` | `read` and: uploads and deployments, promote, roll back, cancel, redeploy, set and remove secrets, add, verify and remove domains, delete a preview, the Console tab's actions, redrive a platform run        |
| `admin`  | `deploy` and: create, delete and restore apps, change the promotion rule, revoke any key, mint, rotate and revoke the database's read string                                                                  |

A key never opens: another organization (a miss is a 404), a secret's value (the platform keeps none), the database's owner credential, the hosting or the database provider's account, or a new key.

### Mint and revoke

```bash
durable-sdk keys list
durable-sdk keys list --json
durable-sdk keys list --owner user:<id>
durable-sdk keys revoke <id>
```

```bash
curl -s https://durablesdk.com/api/v1/keys \
  -H "Authorization: Bearer $DURABLE_API_KEY"
curl -s "https://durablesdk.com/api/v1/keys?owner=user:<id>" \
  -H "Authorization: Bearer $DURABLE_API_KEY"
```

`owner` narrows the list to the keys one person minted (`user:<id>`, the `owner` each key carries); the Members page links a person's key count to that list. A member revokes a key they minted; an admin revokes any. A revoked or expired key answers 401 to its next request.

### Rotation

There is no in-place rotation: mint a new key, move the consumer to it, revoke the old one. A key's expiry is the forcing function; set a calendar reminder to the expiry `keys list` prints. Two keys may stand for the same job while the swap lands.

## The CLI's login

`durable-sdk login` is a device flow. The CLI opens a login with the platform (no credential, ten an hour per address), prints a URL and an eight-character code, opens the browser where one is, and polls every five seconds.

```bash
durable-sdk login
```

```text
open https://durablesdk.com/cli/authorize?code=XXXX-XXXX and confirm the code XXXX-XXXX
durable-sdk login: acme as durable-sdk on laptop, scope deploy, expires 2027-01-26T12:00:00.000Z; stored for https://durablesdk.com
```

On `/cli/authorize`, signed in with the organization chosen, the page shows the client, the hostname, the organization and the scope asked, and one press approves. Approve mints a key named `<client> on <hostname>` with a 90-day expiry at most your role's scope and at most the one asked (`--scope read|deploy|admin`, default `deploy`); the CLI's next poll receives it once. Deny ends the login (`plane.login.denied`); a login older than ten minutes is `plane.login.expired`; polling early is `plane.login.slow_down`; five wrong codes in ten minutes expire that person's attempts.

```bash
echo "$DURABLE_API_KEY" | durable-sdk login --with-key
```

`--with-key` reads a key from stdin (a CI job, an agent), proves it with `GET /whoami`, and stores it. `durable-sdk whoami` prints the organization, the key's name, scope and expiry; `durable-sdk logout` deletes the entry.

### Where the key is kept

The CLI writes `credentials.json` (mode 0600 in a 0700 directory) under `$DURABLE_CONFIG_DIR`, else `$XDG_CONFIG_HOME/durable-sdk`, else `~/.config/durable-sdk`, keyed by the platform's base URL, with the organization, the key's name, scope and expiry beside it. The value is never printed.

Precedence: `DURABLE_API_KEY` in the process environment wins over the file. `DURABLE_PLANE_URL` points the CLI at another platform (a test's fake) and is honoured only when it and `DURABLE_API_KEY` both come from the process environment, never from a project file. The CLI sends a key over `https://` alone (`http://localhost` excepted) and only to the base URL the key was stored under; a mismatch is refused by name before any request (`plane.cli.plane_mismatch`). The whole environment table is in [the CLI reference](https://durablesdk.com/docs/reference/cli.md).

### A key for an agent

An agent on a laptop runs `durable-sdk login` like a person and approves in the browser. An agent in a job holds a key a person minted from `/dashboard/keys` with the `deploy` scope and a 90-day expiry, in `DURABLE_API_KEY`, and never a longer-lived or wider one; [the agents page](https://durablesdk.com/docs/reference/mcp-and-agents.md) has the first commands to run.

## Rate limits at the door

Each key 600 requests a minute, each person 600, each organization 2 000 across every principal, 60 deployments an hour, 10 app creations an hour, 120 Console requests a minute, 10 logins an hour per address. A 429 carries `Retry-After`; a tier may raise a number ([usage and limits](https://durablesdk.com/docs/hosting/usage-and-limits.md)).

---

Prompt for an agent:

```text
Read https://durablesdk.com/docs/operate/accounts-and-keys.md, then mint an API key with the deploy scope for a CI job and log the CLI in with it; run durable-sdk doctor --host before and after; a refused line is a refusal id: durable-sdk explain <id>
```
