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.
Authenticate with a personal access token
Section titled “Authenticate with a personal access token”- Sign in to the dashboard.
- 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. - 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.
export BASE_API=https://<management-api-url>export PAT=pb_pat_...curl -s -H "Authorization: Bearer $PAT" $BASE_API/v1/projectsRecipes
Section titled “Recipes”Create a project and wait until it is active:
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, andNOT NULLadded on a table that has rows;locks: the locks the SQL took, with the table’s estimated rows (ACCESS EXCLUSIVEblocks reads and writes until the real migration commits);policy_gateandwould_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 ownchanges,breaking,locks(the locks that script took) andpolicy.statusisplanned,failed(onlyerror.code,error.sqlstateand the message, never row data),non_transactional(not run, see below) ornot_planned(after a failed or non-transactional script,reasonsays which);complete:truewhen every script was planned.would_applyisfalseotherwise, 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):
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/migrationsApply several migrations in order (for example the migrations of one app). Each runs in its own transaction as the project owner:
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 outappfor 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 answers409 migration_checksum_mismatchand nothing runs. - Order and failures: migrations run in order and stop at the first failure. The answer
{ ok, results[] }reports each one asapplied,skipped,failed(witherror.sqlstate) ornot_run, plus theNOTICElines it printed inlogs. It is200, or422when 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 gets422 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 whenIF NOT EXISTSskipped it) is409 index_conflictand 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
reconciledwithout 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:
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/previewGenerate an owner-only policy (preview first with ?dry_run=true):
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}} |
Database introspection pages
Section titled “Database introspection pages”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 inpartitions_truncated). Bounds longer than 512 characters are cut and markedbound_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 withpartition_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 withdetails_truncatedlost their roles and USING/CHECK text),partitions_truncated,grants_truncated,advisors_truncated.
Behavior to rely on
Section titled “Behavior to rely on”- Roles:
vieweris read-only;developermanages schema, policies, config and webhooks;owneralso 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). Sendnullto 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-Afteron 429. - Plan gating: writes that need a feature outside your plan answer
402 feature_not_in_plan; limits answer402 plan_limit_exceeded. See Plans and limits. - During a restore the project is in
maintenanceand project routes answer503 project_maintenancewithRetry-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.