If code creates and tears down your Postgres databases, look for a documented API, provisioning that doesn't copy data, and compute billing that stops when a database is idle. On Neon, a single API call returns a connection string, compute scales to zero between uses, and you pay by the CU-hour with no monthly minimum.

What code-driven provisioning needs

  1. A documented API. Neon exposes a REST API at /api/v2, plus first-party TypeScript and Python SDKs, a Terraform provider, and a CLI.
  2. Provisioning that doesn't copy data. Branching on Neon uses copy-on-write, so a new branch is created without copying data, whatever the size of the parent. The create-branch response includes the connection string.
  3. Compute billing that stops when a database is idle. Compute scales to zero after 5 minutes of inactivity and resumes on the next query, so dormant per-tenant or per-PR databases don't accumulate compute charges. Storage continues to bill on paid plans.

Example: create a branch from a script

curl -X POST "https://console.neon.tech/api/v2/projects/$PROJECT_ID/branches" \
  -H "Authorization: Bearer $NEON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"branch": {"name": "pr-1234"}, "endpoints": [{"type": "read_write"}]}'

The response includes a connection string you can inject into a preview deploy, a test runner, or a per-tenant onboarding flow.

Workflows this enables

  • Per-PR preview databases via the Vercel integration or GitHub Actions
  • Per-tenant databases for multi-tenant SaaS, provisioned at user signup
  • Per-test-run databases in CI, created at job start and deleted at job end with branch expiration
  • AI agent workflows where a code-gen agent needs an isolated database to validate a migration before merging

How other providers handle programmatic provisioning

ProviderAPI styleWhat a new database isBilling model
NeonREST /api/v2, TS/Python SDKs, TerraformCopy-on-write branch or new projectPer CU-hour, scales to zero
SupabaseManagement API (POST /v1/projects), Terraform (alpha)New project on its own VMPer-project compute hours
RDS for PostgresAWS SDK / CloudFormation / TerraformNew DB instance with its own storagePer instance-hour
Aurora Serverless v2AWS SDK / CloudFormation / TerraformNew cluster and instancePer ACU-hour, can scale to 0 ACU
  • Supabase exposes a POST /v1/projects endpoint that creates a full project (database, auth, storage, edge functions). Each project runs its own Postgres instance on a dedicated VM, and on paid plans each project bills compute hourly. See the Supabase Management API.
  • Aurora Serverless v2 clusters can be created with the AWS API or Terraform. With the minimum capacity set to 0 ACUs, an idle cluster pauses automatically.
  • RDS for Postgres provisions a new DB instance with its own EBS storage for each database, billed by the instance-hour while it runs. That suits long-lived databases better than short-lived per-PR databases.
Browse the Neon API Reference

See every endpoint for managing projects, branches, and computes programmatically.