# Account administration

Account operations use the selected service connection and workspace. Discover
the same capabilities through the CLI, Python SDK, MCP, or the HTTP OpenAPI
contract. The browser settings page can also create and copy workspace invitation links.

```sh
op-sys auth login --endpoint https://records.example.com
op-sys workspaces list
op-sys selection update --workspace <workspace-id>
op-sys memberships list --workspace-id <workspace-id>
```

Use `--connection <name>` before a command to choose another saved service.
Pass `--workspace-id` explicitly when creating, listing, or revoking invitations. Billing, keys and
service reads stay pinned to the selected connection and workspace.

## Workspace membership

| Capability | Effect |
| --- | --- |
| `workspaces.list`, `workspaces.create` | Discover or create workspaces. |
| `memberships.list` | List members and their current role and revision. Follow `next_after` with `after`. |
| `memberships.update` | Set a role using `member_id`, `expected_revision` and `role`. |
| `memberships.remove` | Remove a member using their current revision. |
| `invitations.create` | Create a one-time Member invitation for a specific email. |
| `invitations.inspect` | Preview the workspace name, offered role and expiry using the link. |
| `invitations.accept` | Join with a signed-in account whose verified email matches the invitation. |
| `invitations.list` | List invitations, their recipients and status. Follow `next` with `after`. |
| `invitations.revoke` | Withdraw an invitation by ID. Use memberships to manage a person who already joined. |

Workspace owners manage invitations and roles. The service protects the last
owner and checks membership revisions. For collaboration in one ledger, use
[ledger invitations](/docs/raw/manuals/ledger-core.md#invite-a-participant-to-a-ledger).
Ledger permissions are granted independently of workspace membership.

### Send and accept a workspace invitation

```sh
op-sys --output json invitations create --workspace-id <workspace-id> --email colleague@example.com
# Share the returned url with the recipient.
op-sys invitations inspect --invitation "$INVITATION_URL"
op-sys invitations accept --invitation "$INVITATION_URL"
```

The link expires after 24 hours by default. The recipient may preview it before
sign-in. The preview omits their email. Accepting requires the invited address
to be verified by the service's identity provider. Sign-in alone leaves the
invitation pending. The browser offers **Join workspace** after sign-in and
**Open workspace** after acceptance. The post-join handoff includes the service
and workspace to use from a separate terminal or agent.

```sh
op-sys --connection local auth login --endpoint <service-url> --workspace <workspace-id>
```

Once ready, `op-sys ledgers list` shows ledgers shared with that account.
The post-join handoff carries the destination and requires ordinary account
access.

Interactive acceptance guides sign-in and selects the joined workspace.
Structured clients use the sign-in and selection actions returned by acceptance.
If another service is selected, use a connection for the service in the link.
Repeating acceptance with
the same account can recover its receipt while the membership is current and
the invitation remains unrevoked.
Copy and send the link using your preferred channel.

### Call the HTTP operations

Use `/v1/workspaces` for workspace discovery and creation,
`/v1/workspaces/{workspace_id}/memberships` for roles, and `/v1/invitations` for
links. To create a membership invitation, POST `workspace_id`, `email`, an
`invitation_id` UUID, and a `token` of 32 random bytes encoded as lowercase hex.
Save both to retry the same request with the same email and expiry. The service
returns `link_base`. Append `#` and the original token to produce a link such
as `https://veylar.org/i#TOKEN`. Keep the link private. To resolve the link to
its API endpoint, workspace ID, and invitation ID, POST `{"token":"TOKEN"}`
to `/i/resolve` on the link's account host.

POST `workspace_id`, `invitation_id`, and `token` to
`/v1/invitations/inspect` or `/v1/invitations/accept`. Acceptance
requires a signed-in account. The fragment stays out of the page request and
the operation proof stays out of the API URL. Owner lists contain metadata
without the link proof.

Use `GET /v1/invitations?workspace_id=…` to list invitations and
`POST /v1/invitations/revoke` with `workspace_id` and `invitation_id` to revoke.
Existing workspace and ledger links also work with `invitations inspect`
and `invitations accept`.

## API keys

`api_keys.list/create/revoke` manage service credentials with administrative
permission. Keys identify callers; a key alone does not grant access to every
ledger. Supported scopes are `connection`, `read`, `ingest` and `admin`.

```sh
op-sys api-keys create --name agent-reader --scope read \
  --output-file /private/veylar-keys/reader.key
op-sys connections create --name reader --endpoint https://records.example.com
op-sys --connection reader auth login \
  --credential-file /private/veylar-keys/reader.key --credential-scope read
op-sys api-keys list
op-sys api-keys revoke --key-id <key-id>
```

Create saves the one-time key in a **new private file** and returns metadata and
its path. It never prints the key in CLI or MCP output. The parent is secured as
a private directory, so choose a dedicated credential directory. Existing files
and unsafe paths are rejected before creation. An unsuccessful attempt can leave
an empty private file. Creation is not idempotent: if the response or disk write
is lost, inspect keys and revoke the uncertain key before explicitly creating
another. No automatic creation retry occurs.

Optional `restrictions` use the service's existing source/namespace allowlists,
raw-payload permission and query limit. They constrain service access; ledger
grants remain independently enforced. Static deployment keys appear in list
results but must be rotated through deployment configuration.

HTTP uses GET/POST `/v1/access/api-keys` and DELETE
`/v1/access/api-keys/{key_id}`. POST returns the secret once to the authenticated
HTTP caller, who is responsible for custody; `output_file` is a supplied-client
input. Revocation returns HTTP 204; supplied clients return `revoked: true`.
Revocation never deletes a caller's local credential file.

## Billing and usage

`billing.get` returns organization usage, estimated charges and monthly invoices.
`usage.get` returns authorized organization usage and the assigned plan metadata.
Organizations start on Core; assignment alone does not activate paid usage.

`billing.manage` opens organization payment management through Stripe when the
service enables it. It requires a signed-in owner or admin; an API key cannot
create a billing session. Use `client.billing.manage()` or `op-sys billing manage`
with the selected organization. When first adding payment details, supply a billing
email with `client.billing.manage(billing_email="billing@example.com")` or
`op-sys billing manage --billing-email billing@example.com`. The provider retains
that contact; later changes happen in the hosted portal. The response contains a private, temporary URL;
open it to manage payment methods and invoices. Request another session if the
link expires. Returning to Veylar does not prove that payment setup succeeded.
Billing uses verified Stripe state, while estimates remain separate from invoices.

`billing.setup` records the signed-in owner's agreement to the displayed Terms
and usage pricing using `terms_version`, `terms_fingerprint` and
`pricing_fingerprint`. These values come from workspace setup; callers cannot
supply prices. The browser includes this agreement in normal workspace creation. Hosted first-use login returns `workspace_setup_required` and a setup URL instead of accepting Terms automatically. Explicit `workspaces.create` calls can pass the same three reviewed fingerprint fields; customer-hosted creation does not require cloud billing.
After payment verification, setup completes automatically. There is no separate
paid-usage switch or default free cloud evaluation. Unconfigured workspaces cannot
start billable writes, searches or storage growth.

Terms are published as immutable dated versions. Material updates appear in owner
notices ahead of their effective date. Fresh owner agreement can be requested for
material changes; API activity and notice delivery are not consent. Routine edits
do not repeatedly prompt. Publishing Terms or rates does not rewrite an existing
workspace's frozen commercial agreement or prior invoices.

Monthly invoices retain their accepted plan version. Managed usage tracks accepted
records, logical storage and search requests in separate units. Quantities and
minor-currency amounts are decimal strings; retain their precision. An unset
estimate is `null`, not a zero price. Estimates are separate from finalized invoices.

`billing.get` also returns `billing_access`: the verified access state, whether new
billable work is allowed, and any payment grace deadline. An overdue invoice can
pause new billable work while preserving reads, export and deletion under existing
permissions. Resolve payment through Billing; adding a payment method alone does
not settle an outstanding invoice. A restricted operation returns `payment_required`
with recovery guidance. Local-only operation does not acquire cloud billing.

A request spending limit bounds new writes and searches; retained storage continues
to accrue separately. Billing availability depends on the selected installation;
customer-hosted services do not use Veylar-managed billing.

```python
from op_sys import OpSys
client = OpSys(connection="work")
summary = client.billing.get()
usage = client.usage.get()
```

## Organization deletion

`deletion.status/request/cancel` concern the **organization and its retained
data**, not deletion of one ledger or the user's identity at every service.
Request and cancellation require a current owner session. `confirm_tenant` must
match the exact organization. Cancellation binds to `deletion_id` and `generation`
from the current status; stale requests fail without changing the lifecycle.

```sh
op-sys deletion status
op-sys deletion request --confirm-tenant <organization-id>
op-sys deletion cancel --deletion-id <request-id> --generation <generation>
```

The configured service worker advances eligible deletion after the grace period
and legal holds permit it. Cancellation is available only while the service's
state allows it. Previously revoked API keys remain revoked after cancellation.
Status also supports an authorized admin key. For request and cancellation,
a saved browser session is used by default; private `session_token_env` or
`session_token_file` references support owner-session recovery. Tokens never
appear in output. These are alternative credential inputs, not authorization
bypasses. Inspect status before retrying an uncertain mutation.

## Diagnostics with distinct purposes

| Operation | Question answered |
| --- | --- |
| `doctor`, `self version`, `mcp doctor` | Is the local installation or MCP transport working? |
| `selection.get`, `auth.status` | What context and authentication have I selected? |
| `service.health` | Is the configured service alive? No credentials are sent. |
| `service.inspect` | What service posture, usage and counters can this caller inspect? |
| `service.metrics` | What service counters can this caller read? |
| `connections.check` | Which connection, identity or account-access check needs attention? |

A successful health check does not prove account access. A failed diagnostic
permission check does not mean the service is offline. `connections.check`
returns separate checks with recovery guidance and does not repair or upload
anything. Restricted keys may intentionally lack diagnostic-read permission.

The old `cloud team`, `cloud deletion`, `cloud billing`, `cloud checkout`,
`cloud usage`, `cloud status`, `cloud doctor`, `cloud metrics` and `cloud diagnostics`
commands and corresponding SDK/MCP names are removed, without aliases.
