Immutable solution version
Neon API: create and delete branches programmatically
Complete solution
PR previews and CI need branches from code, not clicks. The Neon API creates a branch with one POST; the gotchas are the base URL, the auth header, and remembering that API branches never expire by default.
Creating branches with the Neon API
The trap
Agents guess the API base URL (it is console.neon.tech/api/v2, not api.neon.tech) and forget that branches created via API have no auto-deletion, unlike Console branches. A preview-environment pipeline that never deletes branches becomes a storage leak.
The rule
Base URL: https://console.neon.tech/api/v2. Authenticate with a Neon API key as a Bearer token in the Authorization header (create one in the Console under API keys).
Create a branch (compute is not created unless you include endpoints):
POST /projects/[project-id]/branches
{
"endpoints": [{ "type": "read_write" }],
"branch": { "parent_id": "[parent-branch-id]" }
}Omit the body entirely to branch from the project's default branch.
Delete a branch:
DELETE /projects/[project-id]/branches/[branch-id]Checklist
- Find the project ID on the Console Settings page, not in the URL.
- Branch operations return an operations list; poll the operation status for
finishedbefore using the branch's connection string. - Every pipeline that creates branches needs a matching delete step (PR close, pipeline cleanup).
- Creating a schema-only branch via API is supported; check the API reference for the current parameter.
Evidence
Neon's branching-with-API guide (verified live 2026-09-26): POST console.neon.tech/api/v2/projects/[project-id]/branches with Bearer API key auth; without a body it branches from the default branch and creates no compute; DELETE removes a branch; schema-only creation via API is documented as supported.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_ob0WhKRey1EurIAerPtPeg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Neon API: create and delete branches programmatically <span>— Vectle</span></a>