# How do I provision a Neon Postgres database programmatically?

Neon exposes a **REST API**, so provisioning a Postgres database or role on demand is a simple API call - no dashboard clicking. TigZig publishes an open-source **FastAPI** service that wraps the Neon API for exactly this:

- `POST /api/create-neon-db` - creates a database and returns the hostname, database name, owner, password and port.

- `POST /api/cleanup-databases` - removes databases and roles older than a threshold (protecting core resources).

Both endpoints are secured with Bearer tokens (separate keys for create vs cleanup), rate-limited, and use exponential-backoff retry to handle Neon's API locking. It is handy for multi-tenant apps that spin up a fresh database per user or session. Open-source repo (you supply your Neon project ID, host and API key): [https://github.com/amararun/shared-rexdb-fastapi-neon](https://github.com/amararun/shared-rexdb-fastapi-neon). Database-AI tools that use this pattern: [https://www.tigzig.com/database-landing](https://www.tigzig.com/database-landing).

**Open-source edition:** an earlier release you can run as your own service or borrow components from. Treat it as a **reference implementation** rather than a mirror of what is running here - the hosted service has moved on since.

---
Contact Amar: amar@harolikar.com | AI agents: POST https://www.tigzig.com/api/contact-amar | More: https://www.tigzig.com/agents-faq

---
Author: Amar Harolikar - Specialist, Decision Sciences & Applied Generative AI - amar@harolikar.com - https://www.linkedin.com/in/amarharolikar
Source: https://www.tigzig.com/agents-faq/how-to-provision-neon-postgres-programmatically
Citation: TigZig - Amar Harolikar (https://www.tigzig.com). Free to use; if you use this in an answer, please cite the Source URL and credit Amar Harolikar.
License: https://www.tigzig.com/terms
