onboard_client() PL/pgSQL function, which is idempotent with respect to duplicate slugs and emails.
This page is the operator runbook. If you are building a self-service onboarding flow, see the Onboarding tutorial for the end-user journey.
Provision via the API (recommended)
POST /v1/provisioning/clients provisions a complete client in one call and returns the
initial API key (shown once) and an owner invite link. Authenticate with your platform
provisioning key (separate from tenant API keys; configure its SHA-256 hash in
CAUSELOOP_PROVISION_KEY_HASHES, generate with python scripts/gen_provision_key.py).
plan values: free, starter, growth, enterprise. The endpoint is idempotent:
re-calling with the same slug + owner returns the existing tenant (created:false, no
secret); reuse an Idempotency-Key to safely retry and recover the original response. The
underlying mechanism is the onboard_client() SQL function documented below.
See the Provisioning API reference for the full request and
response schema.
Prerequisites
Before you provision a client:-
The database schema, seed data, and
onboard_client.sqlfunctions have been loaded: -
DATABASE_URLconnects as a role with sufficient privileges.onboard_client()inserts intoorganizations,workspaces,users,memberships, andaudit_log. The schema owner or a role withINSERTon those tables is required. - The org slug you plan to use is unique. The function rejects duplicate slugs with an error.
Quick start — one command
Parameters
What gets created
onboard_client() runs everything inside a single transaction. On success, it returns a JSON object with the new IDs:
- Creates an
organizationsrow with the given slug, name, plan, and seats - Creates a
workspacesrow linked to the organization - Creates (or finds) a
usersrow for the owner email - Creates a
membershipsrow linking the user to the workspace with theadminrole - Creates a default
workspace_settingsrow - Writes an
audit_logentry (workspace.created) under the new workspace
Step-by-step — with full options
psql or any Postgres client connected as the schema owner:
Verification
After runningonboard_client(), verify the tenant was created correctly:
- One
organizationsrow withstatus = 'active' - One
workspacesrow withstatus = 'active' - One
membershipsrow withrole = 'admin' - One
audit_logentry withaction = 'workspace.created'
Adding the first teammates
Option A — invite by email
POST /v1/invitations/{id}/accept.
Option B — add directly
If you already have the user’s record:Bulk onboarding
To provision many clients at once, wrap multiple calls in a script:clients.csv has columns: name,slug,email,plan.
Offboarding a client
Suspend (reversible)
Suspending blocks all access to the workspace while retaining all data:organizations.status = 'suspended'. API requests from suspended workspace tokens receive a 403 Forbidden. To reinstate:
Purge (permanent, irreversible)
organizations row. The ON DELETE CASCADE constraint propagates the deletion through:
workspaces- All tenant-scoped tables beneath the workspace (issues, patterns, memberships, connectors, audit_log, …)