Skip to content

Management API

The Management API (/v1/*) is the control plane the dashboard itself uses. Anything you can click in the dashboard, you can script. A machine-readable OpenAPI 3.1 spec is available at GET /v1/openapi.json.

  1. Sign in to the dashboard.
  2. Open Account → Access tokens and create a personal access token (PAT) with the scopes you need. The token (pb_pat_...) is shown once. Tokens can expire and be revoked.
  3. Send it as a bearer token.
Scope Allows
projects:read / projects:write projects, keys, config, webhooks, secrets, backups
database:read / database:write tables, policies, migrations, SQL, extensions, advisors
auth:admin project users, providers, tenants
org:admin organizations and members

A write scope implies the matching read scope. org:<uuid> and project:<ref> entries restrict a token to those resources. A PAT can never create or revoke PATs.

Terminal window
export BASE_API=https://<management-api-url>
export PAT=pb_pat_...
curl -s -H "Authorization: Bearer $PAT" $BASE_API/v1/projects

Create a project and wait until it is active:

Terminal window
curl -s -X POST -H "Authorization: Bearer $PAT" -H 'content-type: application/json' \
-d '{"organization_id":"<org uuid>","name":"Shop","ref":"shop"}' $BASE_API/v1/projects # 201, status "provisioning"
curl -s -H "Authorization: Bearer $PAT" $BASE_API/v1/projects/shop # poll until status is "active"

On Cloud, the same request can carry a bootstrap (app roles, app schemas, trusted issuers, Data API) with an Idempotency-Key: see Create a project with bootstrap.

Plan a migration first (dry run): POST /v1/projects/{ref}/database/migrations/plan with { "sql": "..." } (or migrations: [...]) runs the SQL in one transaction that is always rolled back. It returns:

  • changes: what would change, per table, column, index, constraint, policy and function;
  • breaking: dropped tables, columns, views, policies or functions, column type changes, and NOT NULL added on a table that has rows;
  • locks: the locks the SQL took, with the table’s estimated rows (ACCESS EXCLUSIVE blocks reads and writes until the real migration commits);
  • policy_gate and would_apply: what the policy gate would decide for the same SQL from the same caller;
  • items: one entry per script (plan_version: 2), each with its own changes, breaking, locks (the locks that script took) and policy. status is planned, failed (only error.code, error.sqlstate and the message, never row data), non_transactional (not run, see below) or not_planned (after a failed or non-transactional script, reason says which);
  • complete: true when every script was planned. would_apply is false otherwise, since the plan cannot show what all of them would do.

Nothing is kept, but the plan runs on the project database (target: "live"), or on the clone for an ephemeral project ("ephemeral", Cloud). The locks are held while the plan runs: it waits at most 2 seconds for a table in use (409 plan_lock_timeout, nothing changed). On the live database each statement stops after 5 seconds and the whole plan shortly after (409 plan_timeout, nothing changed); max_lock_seconds in the response is that bound. An owner can change it with PATCH .../config/migrations { "plan_timeout_s": 1-30 }. On an ephemeral clone the limit is 30 seconds.

Heavy statements on large tables (more than 1 million estimated rows) are not run on the live database: a column type change, SET NOT NULL, a validated constraint, a default computed per row, or CREATE INDEX without CONCURRENTLY. The response is then status: "skipped_heavy" with the statements, the table and the lock they would hold. Plan them on an ephemeral clone, or add ?allow_heavy=true to run them anyway (the table is blocked for up to max_lock_seconds). A script with SQL that cannot run in a transaction (CREATE INDEX CONCURRENTLY, COMMIT) is not run: its item is non_transactional (for a concurrent index with the table and its lock, SHARE UPDATE EXCLUSIVE, which blocks no reads or writes) and the scripts after it are not_planned. Needs database:write; service accounts need db:migrate.

Apply a migration from CI (idempotent: replaying the same version and checksum returns 200):

Terminal window
jq -n --arg sql "$(cat potalab/migrations/20260929120000_create_todos.sql)" \
'{name:"20260929120000_create_todos", sql:$sql}' |
curl -s -X POST -H "Authorization: Bearer $PAT" -H 'content-type: application/json' -d @- \
$BASE_API/v1/projects/shop/database/migrations

Apply several migrations in order (for example the migrations of one app). Each runs in its own transaction as the project owner:

Terminal window
curl -s -X POST -H "Authorization: Bearer $PAT" -H 'content-type: application/json' -H 'Idempotency-Key: deploy-42' \
-d '{"app":"app_crm","migrations":[{"version":"0001","sql":"create table app_crm.leads (id bigint primary key)"},{"version":"0002","sql":"..."}]}' \
$BASE_API/v1/projects/shop/database/migrations/batch
  • Versions are opaque, sortable strings (0001, 20260929120000, …) per app; leave out app for the project’s own migrations. checksum (sha256 of the SQL) is optional and verified when sent.
  • Repeats: a version already applied with the same SQL is skipped. With different SQL the whole request answers 409 migration_checksum_mismatch and nothing runs.
  • Order and failures: migrations run in order and stop at the first failure. The answer { ok, results[] } reports each one as applied, skipped, failed (with error.sqlstate) or not_run, plus the NOTICE lines it printed in logs. It is 200, or 422 when one failed.
  • One run per project at a time: a second run gets 409 migration_in_progress.
  • Idempotency-Key: a successful answer is replayed for 24 h (header idempotent-replayed: true). The same key with another body gets 422 idempotency_key_reused. Failed answers are not stored, so retrying with the same key runs again. A request interrupted by a crash frees its key after 2 minutes.
  • History: GET .../database/migrations?app=app_crm.

Policy gate: the permission diff of each migration is computed inside its transaction.

Gate Effect
report (default for people: dashboard sessions and personal access tokens) never blocks; the report is in the answer (policy) and in the audit log
warn / error an unacknowledged change of that level (error, or warn and error) rolls the migration back: 422 policy_check_failed with the report
off no diff

Acknowledge a change on purpose with policy_ack: [{ code, object?, reason }] or a -- policy-ack: <code> comment in the SQL. Acknowledgements are recorded in the audit log. Service accounts run with error by default and cannot acknowledge findings. Set the gate per project with PATCH /v1/projects/{ref}/config/migrations { "policy_gate": "off" | "report" | "warn" | "error" } (project owner).

Transaction control is refused. A migration may not contain BEGIN, COMMIT, END, ROLLBACK or statements that cannot run in a transaction (VACUUM, …): non_transactional_statement. As a second check, Base verifies after the script that its transaction is still the same. If it is not, the answer is migration_left_transaction, and the changes may have been committed: check the database before you retry.

Concurrent indexes. A migration that is exactly one CREATE [UNIQUE] INDEX CONCURRENTLY [IF NOT EXISTS] name ON schema.table (...) or DROP INDEX CONCURRENTLY [IF EXISTS] schema.name runs outside a transaction, so reads and writes of the table go on during the build. Put it in a migration of its own: mixed with other statements, or without the schema, it is 400 non_transactional_statement. Base then checks the result:

  • the index must exist on that table, be valid and match the statement. A failed or invalid build is removed again (400 index_invalid). An existing index of that name with another definition (also when IF NOT EXISTS skipped it) is 409 index_conflict and nothing is recorded;
  • tables and indexes of Base-managed schemas (auth, storage, base, …) or of extensions are refused (403 index_target_not_allowed), and so is dropping an index that backs a constraint (409 index_in_use: drop the constraint instead);
  • run again after an interruption, the same migration finds the finished index (or the dropped one gone) and records it as reconciled without building again.

There is no policy diff for these (an index changes no permission). The build waits for transactions already writing the table and stops at the migration time limit.

Lost run lock: if the run lock of the project is lost before a migration is recorded, the answer is 409 migration_lock_lost and nothing is recorded; run it again.

Run as the app: app migrations can run as the app’s own migrator role instead of the project owner ("run_as": "migrator" with app): see App roles. A ledger marker that Base did not write gives 409 migration_marker_drift and nothing runs.

Never applied twice: each migration also writes a marker in the project database, in its own transaction. If the platform record is lost (for example a crash right after the commit), the next run restores it from the marker (status: "reconciled") instead of running the migration again.

Preview what a migration changes in permissions (applied in a rolled-back transaction, nothing is stored). The answer lists changes[] (anon_exposed, policy_widened, rls_disabled, …) with a level per change, the same report as potalab base db push --dry-run:

Terminal window
jq -n --arg sql "$(cat potalab/migrations/20260929120000_create_todos.sql)" '{sql:$sql}' |
curl -s -X POST -H "Authorization: Bearer $PAT" -H 'content-type: application/json' -d @- \
$BASE_API/v1/projects/shop/database/migrations/preview

Generate an owner-only policy (preview first with ?dry_run=true):

Terminal window
curl -s -X POST -H "Authorization: Bearer $PAT" -H 'content-type: application/json' \
-d '{"table":"public.todos","command":"all","mode":"owner","owner_column":"owner_id"}' \
"$BASE_API/v1/projects/shop/database/policies?dry_run=true"
Task Request
Make a table tenant-scoped (admin; add ?dry_run=true to preview) POST /v1/projects/shop/database/tenancy {"table":"public.projects","entitlement":"projects"}
List tenant-scoped tables and drift GET /v1/projects/shop/database/tenancy
Enable realtime PATCH /v1/projects/shop/config/realtime {"enabled":true,"tables":["public.todos"]}
Create a secret key (shown once) POST /v1/projects/shop/api-keys {"kind":"secret","name":"backend"}
Run the security advisor GET /v1/projects/shop/advisors
Describe the database for an AI tool (tables, columns, FKs, RLS, policies, grants per role, advisor findings; ?schema= any schema of the project, exposed or not, default the exposed ones; ?table=, ?cursor=). Policy and default texts are your own SQL and may contain literals GET /v1/projects/shop/database/introspect
See plan features GET /v1/projects/shop/features
Tune rate limits (owner) PATCH /v1/projects/shop/config/rate-limits {"user":{"rps":30}}

GET .../database/introspect returns pages of at most 1 MiB. Follow next_cursor until it is null; every table comes exactly once.

  • Partitions: a partitioned table lists its partitions under partitions (at most 200, the rest counted in partitions_truncated). Bounds longer than 512 characters are cut and marked bound_truncated. Partitions are left out of the list of tables unless you pass ?include_partitions=true. Each partition then comes as an entry of its own with partition_of, its bound, and its own row level security and policies: a partition queried directly does not use the parent’s.
  • A table too big for one page: it comes in a reduced form and the page names it in table_truncated. Row level security flags and policy names are always kept. What was left out is counted: columns_truncated, foreign_keys_truncated, policies_truncated (policies with details_truncated lost their roles and USING/CHECK text), partitions_truncated, grants_truncated, advisors_truncated.
  • Roles: viewer is read-only; developer manages schema, policies, config and webhooks; owner also manages keys, secrets, SMTP, rate limits, the audit log, backups and project deletion. A non-member gets 404, not 403.
  • Audit: every write is recorded, including denied attempts. Owners read it with GET .../audit-log.
  • Config changes propagate to the data, auth and realtime services in about a second.
  • PATCH changes only the keys you send, also inside nested sections (mfa, rate_limits, limits, mappings). Send null to remove a key; lists and maps (email_templates) are replaced as a whole. See Breaking changes.
  • Rate limit: 600 requests per minute per IP. Honor Retry-After on 429.
  • Plan gating: writes that need a feature outside your plan answer 402 feature_not_in_plan; limits answer 402 plan_limit_exceeded. See Plans and limits.
  • During a restore the project is in maintenance and project routes answer 503 project_maintenance with Retry-After.

Direct database connection strings are not available over the API. For types, GET /v1/projects/{ref}/database/access returns the schema description (tables, RLS, grants, policies, functions) with a token that has database:read; the CLI (potalab base gen client) and the MCP tool generate_typescript_types build on it.