# OpenAccount for AI agents

OpenAccount is the system of record for who may act for a business. Agents never get ownership.

## Rules
1. A business id in a request is only a selector. The server proves access on every call; foreign ids return 404.
2. Owners and admins decide; operators run; viewers read. Agency staff are capped by the client's delegation.
3. Every change is written to the business activity log with the actor and the agency it came through.
4. Money is integer minor units plus an ISO-4217 currency. Never send floats.

## Getting a token
POST https://dev.openaccount.run/api/v1/auth/login with {"email","password","client":"api"} returns {"token"}. Send it as `Authorization: Bearer <token>`.

## Operations
- `GET /api/health` — Liveness and database check
- `GET /api/revision` — Deployed git revision
- `POST /api/v1/auth/register` — Create a person with email + password
- `POST /api/v1/auth/login` — Sign in with email + password
- `POST /api/v1/auth/logout` — Revoke the current session
- `GET /api/v1/me` — Current person, sign-in methods and businesses
- `POST /api/v1/businesses` — Create a business or agency (caller becomes owner)
- `GET /api/v1/businesses` — Businesses the caller belongs to or manages via an agency
- `GET /api/v1/businesses/{id}` — Business detail and the caller's effective access
- `GET /api/v1/businesses/{id}/members` — List members
- `PATCH /api/v1/businesses/{id}/members/{personId}` — Change a member role (last owner protected)
- `DELETE /api/v1/businesses/{id}/members/{personId}` — Remove a member or leave
- `POST /api/v1/businesses/{id}/invitations` — Invite by email or E.164 phone; returns a one-time share link
- `GET /api/v1/businesses/{id}/invitations` — List invitations
- `DELETE /api/v1/businesses/{id}/invitations/{invitationId}` — Revoke a pending invitation
- `POST /api/v1/invitations/accept` — Accept an invitation (recipient must be verified)
- `GET /api/v1/businesses/{id}/activity` — Append-only activity log, newest first
- `POST /api/v1/auth/passkeys/register/options` — Start adding a passkey to the signed-in person
- `POST /api/v1/auth/passkeys/register/verify` — Finish adding a passkey (WebAuthn attestation)
- `GET /api/v1/auth/passkeys` — List the caller's passkeys
- `DELETE /api/v1/auth/passkeys/{credentialId}` — Remove a passkey (the last sign-in method is kept)
- `POST /api/v1/auth/passkeys/login/options` — Start a passkey sign-in
- `POST /api/v1/auth/passkeys/login/verify` — Finish a passkey sign-in (WebAuthn assertion)
- `POST /api/v1/auth/apple/nonce` — Single-use nonce for native Sign in with Apple
- `POST /api/v1/auth/apple` — Sign in with Apple identity token (iOS app)
- `DELETE /api/v1/me` — Delete the caller's account (fresh sign-in; sole owners must transfer or close first)
- `GET /api/v1/integrations` — Apps OpenAccount can connect and their readiness
- `GET /api/v1/businesses/{id}/connections` — Connected apps and their state
- `POST /api/v1/businesses/{id}/connections` — Connect an app (409 integration_unavailable until its adapter is live)
- `PATCH /api/v1/businesses/{id}/connections/{connectionId}` — Pause, resume (needs sign-in again) or disconnect
- `POST /api/v1/businesses/{id}/agency-invitations` — Invite an agency with a Read, Prepare or Run preset; returns a one-time link
- `GET /api/v1/businesses/{id}/agency-invitations` — List agency invitations
- `DELETE /api/v1/businesses/{id}/agency-invitations/{invitationId}` — Revoke a pending agency invitation
- `POST /api/v1/agency-invitations/accept` — Accept an agency invitation for one of your agencies (plan limits apply)
- `PATCH /api/v1/businesses/{id}/agencies/{relationshipId}` — Pause, resume or remove an agency (agency-owned connections pause)
- `GET /api/v1/businesses/{id}/team` — People, agencies, clients and agents of a business
- `GET /api/v1/businesses/{id}/usage` — Budgets and job counts for a month (?period=YYYY-MM)
- `GET /api/v1/businesses/{id}/plan` — Effective plan, limits and checkout availability
- `POST /api/v1/businesses/{id}/plan/checkout` — Start a paid plan (503 billing_unavailable until a provider is live)
- `GET /api/v1/businesses/{id}/handover-report` — Ownership, access, connections and open work, without credentials
- `POST /api/v1/businesses/{id}/close` — Close a business: ends agency access and disconnects apps
- `GET /api/v1/admin/overview` — Aggregate counts for internal operators only
- `GET /api/v1/businesses/{id}/blueprints` — Agency onboarding templates (?status=active|archived); no personal data or credentials
- `POST /api/v1/businesses/{id}/blueprints` — Create a versioned onboarding template (agency owners/admins)
- `GET /api/v1/businesses/{id}/blueprints/{bid}` — A template with its versions
- `POST /api/v1/businesses/{id}/blueprints/{bid}/versions` — Add a new version; earlier approvals are never widened
- `POST /api/v1/businesses/{id}/blueprints/{bid}/clone` — Clone a template
- `POST /api/v1/businesses/{id}/blueprints/{bid}/archive` — Archive a template
- `POST /api/v1/businesses/{id}/blueprints/{bid}/unarchive` — Restore an archived template
- `POST /api/v1/blueprints/validate` — Validate template content without saving it
- `POST /api/v1/businesses/{id}/onboarding/plan` — Turn an intent into a typed plan from your templates (deterministic, no model call)
- `POST /api/v1/businesses/{id}/blueprints/{bid}/preview` — Permission diff for one client: added, unchanged, narrowed, removed, unavailable
- `POST /api/v1/businesses/{id}/onboarding-runs` — Start an idempotent onboarding run for one client
- `GET /api/v1/businesses/{id}/onboarding-runs` — Onboarding runs (?side=agency|client)
- `GET /api/v1/businesses/{id}/onboarding-metrics` — Onboarding counts and durations
- `GET /api/v1/onboarding-runs/{rid}` — A run with its steps, diff and blockers
- `POST /api/v1/onboarding-runs/{rid}/bindings` — Bind client resources to template slots
- `POST /api/v1/onboarding-runs/{rid}/approve` — Client owner/admin approves this exact diff (covers only this client)
- `POST /api/v1/onboarding-runs/{rid}/advance` — Advance a run; finished steps are never repeated
- `POST /api/v1/onboarding-runs/{rid}/pause` — Pause a run
- `POST /api/v1/onboarding-runs/{rid}/resume` — Resume a paused run
- `POST /api/v1/onboarding-runs/{rid}/cancel` — Cancel a run
- `GET /api/v1/businesses/{id}/health` — Access health; sources that can't be checked are reported as cant_check, never ok
- `GET /api/v1/accounts/health` — Needs-attention summary for every account the caller can see
- `POST /api/v1/businesses/{id}/repairs` — Dry-run a narrowing repair; returns a revision that expires
- `POST /api/v1/repairs/{pid}/apply` — Apply a previewed repair (recent sign-in required; 409 if the state changed)
- `POST /api/v1/repairs/{pid}/discard` — Discard a previewed repair
- `GET /api/v1/businesses/{id}/reports` — Monthly client reports (?period=YYYY-MM)
- `POST /api/v1/businesses/{id}/reports` — Generate a monthly report (idempotent per period and facts)
- `GET /api/v1/reports/{rid}` — A report: final, reserved, estimated and refunded kept apart, exact minor units
- `GET /api/v1/reports/{rid}/csv` — Report as CSV with source and freshness per figure
- `GET /api/v1/reports/{rid}/html` — Report as printable HTML
- `GET /api/v1/businesses/{id}/report-schedule` — Monthly report schedule and recipients
- `PUT /api/v1/businesses/{id}/report-schedule` — Set recipients (current members only; removed people get nothing)
- `GET /api/v1/me/reports` — Reports delivered to the caller in the app
- `POST /api/v1/businesses/{id}/assistant` — Ask about one business; answers cite only records you can see (deterministic)
- `POST /mcp` — MCP (Streamable HTTP, JSON-RPC 2.0), read-only tools, bearer token

## MCP
POST https://dev.openaccount.run/mcp speaks MCP over Streamable HTTP (JSON responses) with the same bearer token. Tools are read-only and
return exactly what the matching REST route returns for the caller.

## Not available yet
Agent grants, app connections and Connect AI are not live; connecting an app returns 409 integration_unavailable.
Paid plans are not on sale; checkout returns 503 billing_unavailable. Do not claim to have performed actions through them.
Onboarding steps for apps without a live adapter stay "unavailable"; report refunds are unavailable until a billing provider is live;
reports are delivered in the app only (no email or WhatsApp yet).

## Onboarding, health and reports
1. Templates hold no personal data or credentials. A new version never widens an approval already given.
2. One client's approval covers only that client and only the exact diff it approved (diffHash).
3. Repairs only narrow access. Preview first, then apply with the returned revision before it expires; a recent sign-in is required.
4. Health status cant_check means the source could not be read. Never report it as healthy.
5. Report money is exact integer minor units as strings; final, reserved, estimated and refunded are separate figures.
