# molted auth

Source: https://molted.email/docs/cli/auth

Authentication commands

| Command | Description |
| - | - |
| [`molted auth signup`](#molted-auth-signup) | Create a new account and store credentials |
| [`molted auth login`](#molted-auth-login) | Log in with email and password |
| [`molted auth init`](#molted-auth-init) | Initialize credentials from an existing API key |
| [`molted auth logout`](#molted-auth-logout) | Clear stored credentials for the active profile |
| [`molted auth login-link`](#molted-auth-login-link) | Hand this workspace to your human: emails them a take-over link, or gives you a claim link or the portal URL (requires an admin, all-mailbox key) |
| [`molted auth keys list`](#molted-auth-keys-list) | List API keys |
| [`molted auth keys create`](#molted-auth-keys-create) | Create a new (optionally scoped) API key |
| [`molted auth keys update`](#molted-auth-keys-update) | Re-scope an existing API key |
| [`molted auth keys revoke`](#molted-auth-keys-revoke) | Revoke an API key |
| [`molted auth profiles list`](#molted-auth-profiles-list) | List all profiles |
| [`molted auth profiles switch`](#molted-auth-profiles-switch) | Switch the active profile |
| [`molted auth profiles current`](#molted-auth-profiles-current) | Show the active profile |
| [`molted auth profiles delete`](#molted-auth-profiles-delete) | Delete a profile |

## Agent context

Authentication manages how your agent connects to the Molted Email platform. There are four ways to authenticate, choose based on your situation:

- New agent, new account:

```bash
molted auth signup --name "My Agent" --email <your human's email> --password s3cret
# → use your human's own email, so for Free they get a take-over email.
#   Don't have it? Use an address on example.com (it reaches no one) and
#   login-link gives you a claim link for them. Never invent an inbox on
#   a real domain. Someone else may read it.
# → creates account, provisions tenant, generates API key, stores everything
# → output: { "tenant_id": "tenant-...", "key_prefix": "mm_live_..." }
```

- Existing account (you have email + password):

```bash
molted auth login --email <account email> --password s3cret
# → logs in, creates a fresh API key, stores credentials
# → each login revokes your earlier active keys labeled "cli" (listed in
#   revoked_previous_cli_keys) and mints a new one; other keys stay valid
```

- Existing API key (from dashboard or another agent):

```bash
molted auth init --key mm_live_abc123...
# → validates the key against the API and stores it
# → key format must be mm_live_..., other formats are rejected
```

- Joining an existing tenant (agent adoption):

```bash
molted adopt claim <token>     # if the owner gave you an invite token
molted adopt request           # device flow, the owner approves in the portal
# → see `molted adopt --help` for the full adoption flow
```

### Credential storage

- File: `~/.molted/profiles/<name>.json` (mode 0600, auto-created)
- Contains: raw\_key, tenant\_id, base\_url, mailbox\_url (optional), session\_cookie (if logged in)
- Override with `MOLTED_API_KEY` env var (takes priority over stored key)
- Override config dir with `MOLTED_CONFIG_DIR` env var
- Override mailbox URL with `MOLTED_MAILBOX_URL` env var or `--mailbox-url` flag

### Named profiles

- Save to a specific profile: `molted auth login --profile staging --email ...`
- Switch active profile: `molted auth profiles switch staging`
- One-off override: `molted --profile staging send --to ...`
- Env var override: `MOLTED_PROFILE=staging molted send --to ...`

Session cookie vs API key:

- All post-auth commands use the API key (Bearer token)
- Session cookies are only needed during signup/login bootstrapping
- `signup` and `login` store the API key; `init` validates an existing key
- No session cookie needed for day-to-day operations

### After authenticating, activate billing before sending

```bash
molted billing status           # → check if sendBlocked is true
molted billing setup --plan solo  # → returns Stripe checkout URL
```

The Free plan needs a person as the owner. An account you signed up is agent-owned, so for Free run:

```bash
molted auth login-link --next /app/settings#plan
# and follow what it returns (below); afterwards activate-free works with
# your existing key
```

### API key management

```bash
molted auth keys list           # list all keys (needs an all-mailbox key)
molted auth keys create --label "worker-2"  # create additional keys
molted auth keys revoke <id>    # revoke a compromised key
```

### To hand off to a human (e.g. for billing setup)

```bash
molted auth login-link          # → { kind, url, expiresAt, note }: follow the note
# kind "takeover": no person owns this workspace and your account's email is
#   an outside inbox (your human's own address, say). Molted emailed that
#   address a link to set a password and take the account over. url is
#   null on purpose and sentTo is masked: tell your human to check their
#   inbox. Your password stops working afterwards; your keys keep working.
# kind "claim": no person owns this workspace and your account's email is
#   one of your Molted mailboxes, or on a reserved domain with no inbox
#   (example.com, .test, .invalid). The url is a claim link (7 days): your
#   human signs in or creates an account and claims the workspace. It
#   never signs anyone in by itself.
# kind "portal": a person owns it. The url is the portal; they sign in with
#   their own login.
# --next /app/settings#plan       # where your human lands afterwards
# requires an admin, all-mailbox key -- a key scoped to one or more
# specific mailboxes gets a 403 (mailbox_scope_denied / insufficient_scope)
```

## Commands

### molted auth signup

Create a new account and store credentials

```bash
molted auth signup [options]
```

| Option | Description | Default |
| - | - | - |
| `--name <name>` | Your name (required) (required) | |
| `--email <email>` | The account email, your human's own if you have it (required) (required) | |
| `--password <password>` | Password (required) (required) | |
| `--profile <name>` | Save credentials to a named profile | |
| `--autonomy-level <level>` | Set autonomy level for default mailbox (1 = full approval, 2 = first-contact, 3 = full auto) (one of: 1, 2, 3) | |
| `--skip-onboarding` | Skip the post-signup onboarding sequence | |

Which email to sign up with. It decides how your human gets Free later.

- Your human's own email, if you have it. They get a take-over email to set their own password and the account becomes theirs.
- No address for them? Use one on example.com, say my-agent-\<random>@example.com. It is reserved and reaches no one, so login-link gives you a claim link to hand them instead.
- Never invent an inbox on a real domain. The take-over email would go to whoever reads it, or to no one.

The account you create here is agent-owned. Paid plans work right away (`molted billing setup --plan solo`). The Free plan needs a person as the owner. When you want Free, run

```bash
molted auth login-link --next /app/settings#plan
```

and follow what it returns. With your human's own email they get an email to set their password and take the account over. With an address on a reserved domain (example.com, .test, .invalid) or one of your Molted mailbox addresses you get a claim link to give them.

### molted auth login

Log in with email and password

```bash
molted auth login [options]
```

| Option | Description | Default |
| - | - | - |
| `--email <email>` | Email address (required) (required) | |
| `--password <password>` | Password (required) (required) | |
| `--profile <name>` | Save credentials to a named profile | |
| `--autonomy-level <level>` | Set autonomy level for default mailbox (1 = full approval, 2 = first-contact, 3 = full auto) (one of: 1, 2, 3) | |
| `--skip-onboarding` | Skip the post-login onboarding sequence | |

### molted auth init

Initialize credentials from an existing API key

```bash
molted auth init [options]
```

| Option | Description | Default |
| - | - | - |
| `--key <key>` | API key (mm\_live\_...) (required) (required) | |
| `--profile <name>` | Save credentials to a named profile | |

### molted auth logout

Clear stored credentials for the active profile

```bash
molted auth logout
```

### molted auth login-link

Hand this workspace to your human: emails them a take-over link, or gives you a claim link or the portal URL (requires an admin, all-mailbox key)

```bash
molted auth login-link [options]
```

| Option | Description | Default |
| - | - | - |
| `--next <path>` | Where your human lands afterwards, a path in the app (e.g. /app/settings#plan) | |

### molted auth keys list

List API keys

```bash
molted auth keys list
```

### molted auth keys create

Create a new (optionally scoped) API key

```bash
molted auth keys create [options]
```

| Option | Description | Default |
| - | - | - |
| `--label <label>` | Key label | |
| `--scope-all` | Scope the key to ALL mailboxes (admin access, also the default with no scope flags) | |
| `--mailbox <id>` | Scope the key to a single mailbox | |
| `--permissions <perms>` | Comma-separated permissions for `--mailbox` (read,send,manage) | |
| `--scope <id:perms>` | Per-mailbox scope \<mailboxId>\[:\<perms>] (repeatable) | |

### molted auth keys update

Re-scope an existing API key

```bash
molted auth keys update [options] <id>
```

| Argument | Description | Required |
| - | - | - |
| `<id>` | | yes |

| Option | Description | Default |
| - | - | - |
| `--scope-all` | Scope the key to ALL mailboxes (admin access) | |
| `--mailbox <id>` | Scope the key to a single mailbox | |
| `--permissions <perms>` | Comma-separated permissions for `--mailbox` (read,send,manage) | |
| `--scope <id:perms>` | Per-mailbox scope \<mailboxId>\[:\<perms>] (repeatable) | |

### molted auth keys revoke

Revoke an API key

```bash
molted auth keys revoke <id>
```

| Argument | Description | Required |
| - | - | - |
| `<id>` | | yes |

### molted auth profiles list

List all profiles

```bash
molted auth profiles list
```

### molted auth profiles switch

Switch the active profile

```bash
molted auth profiles switch <name>
```

| Argument | Description | Required |
| - | - | - |
| `<name>` | | yes |

### molted auth profiles current

Show the active profile

```bash
molted auth profiles current
```

### molted auth profiles delete

Delete a profile

```bash
molted auth profiles delete <name>
```

| Argument | Description | Required |
| - | - | - |
| `<name>` | | yes |

See [CLI overview](https://molted.email/docs/cli.md) for global options, credentials and output format.
