Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

API reference

Neon API reference

Neon serverless Postgres

Identifiers
109
With full guides
73
Types
6

Topics covered

  • Serverless Postgres
  • HTTP/serverless driver
  • Connection pooling
  • Database branching
  • Neon + Drizzle
  • Neon + Prisma
  • Autoscaling
  • Read replicas

Class

NameWhat it does
PoolNeon’s Pool class provides a WebSocket-based connection pool for the serverless driver. Use it for interactive transactions, sessions, or node-postgres compatibility rather than ordinary stateless queries.
ClientNeon’s Client is a WebSocket PostgreSQL client for JavaScript and TypeScript. Use it when an application needs a session, an interactive transaction, or node-postgres compatibility.
PrismaNeonPrismaNeon is Neon’s Prisma driver adapter for serverless applications. Construct it with a Neon connection string and pass it to PrismaClient.

Function

NameWhat it does
neonFunction
drizzleFunction
transactiontransaction() executes multiple Neon SQL queries together in one non-interactive transaction. Call it on the query function returned by neon() and provide an array of queries or a synchronous query-producing callback.
sqlNeon's neon() function creates a tagged-template query function for running Postgres SQL over HTTP. It supports parameter-safe interpolation and exposes a transaction helper for multiple queries in one non-interactive transaction.
poolQueryFunction

Const

NameWhat it does
neonConfigneonConfig configures WebSocket-based Pool and Client connections in Neon’s serverless driver. Use it for settings such as WebSocket construction, pipelining, and proxy behavior.
fetchConnectionCacheConst
BranchingNeon branching creates isolated copy-on-write database branches from current or historical states. Child changes are stored independently, enabling safe development, testing, CI/CD, and recovery workflows.
Database branchingNeon database branching creates isolated copy-on-write clones of a database for development, testing, CI/CD, or recovery. A branch can start from the current or a retained historical state and then diverges independently.
Compute endpointConst
AutoscalingNeon Autoscaling adjusts compute resources up or down as database load changes. Set minimum and maximum CU bounds for a primary compute or read replica; scaling occurs without manual intervention or restarts.
Scale to zeroNeon Scale to Zero suspends an inactive Postgres compute after a timeout and resumes it when a query arrives. It reduces compute usage for intermittently used databases, with a brief startup delay on the first query after suspension.
Read replicasConst
Connection poolingNeon connection pooling uses PgBouncer in transaction mode to multiplex many client connections over fewer PostgreSQL connections. Select it with a connection string whose endpoint ID has the -pooler suffix; use a direct connection when session state is required.
PgBouncerConst
Point-in-time restoreConst
Logical replicationNeon logical replication enables PostgreSQL’s publisher-subscriber change streaming for a project. It permanently changes wal_level to logical and restarts all computes when enabled.
ProjectConst
RoleA Neon role is a branch-scoped PostgreSQL role used for database access and ownership. Neon provides role management through the Console, CLI, API, or SQL, with different default privileges depending on the creation method.
Connection stringA Neon connection string is a standard PostgreSQL URL containing the selected role, password, hostname, and database name. Obtain it from the Console or CLI, store it as DATABASE_URL, and pass it to a PostgreSQL client.
Pooled connectionConst
Direct connectionA direct connection connects straight to Postgres without PgBouncer. Use it for stable, long-lived sessions and operations that require session state, such as migrations or LISTEN/NOTIFY.
Time Travel queriesConst
Schema diffNeon Schema Diff compares the SQL schemas of two branches and displays their differences side by side. It is available in the Console, CLI, API, and GitHub Actions workflows.
Protected branchesNeon protected branches safeguard production or sensitive data by blocking destructive branch, compute, and project operations. They can also trigger fresh child-branch credentials and optionally restrict access through IP Allow.
AutosuspendConst
IP AllowIP Allow restricts connections to a Neon project so that only explicitly trusted IP addresses or ranges can connect. It is available on the Scale plan and supports individual addresses, ranges, and CIDR notation.
OrganizationsConst
MonitoringNeon’s Monitoring dashboard in the Console presents system and database metrics as graphs. Choose a branch and compute, then use the Postgres, Storage, or Functions tabs to inspect the relevant data.
Neon AuthConst
Neon RLSNeon RLS uses PostgreSQL Row-Level Security to restrict table rows according to the authenticated user. Tables exposed through the Neon Data API must have RLS enabled and policies configured.
JWT authorizeNeon authorizes end users through the Data API with JWTs. The token determines the PostgreSQL role used for the query, while GRANT permissions and Row-Level Security control access.
Stack Auth integrationConst
Vercel integrationConst
Drizzle integrationDrizzle integrates with Neon by using Neon's serverless driver as Drizzle's database backend. In serverless applications, create a client with @neondatabase/serverless and pass it to Drizzle's Neon HTTP adapter.
Prisma integrationConnect Prisma ORM to Neon with @prisma/adapter-neon. Use a pooled URL for application queries and a direct URL for Prisma CLI operations such as migrations and schema pushes.
HTTP driverNeon’s HTTP driver uses the neon() function from @neondatabase/serverless to issue Postgres queries through HTTP fetch requests. It is designed for serverless and edge runtimes, especially for single queries and non-interactive transactions.
WebSocket driverThe Neon serverless driver supports WebSocket-based PostgreSQL access through Pool and Client. Use this transport for interactive transactions, sessions, or node-postgres compatibility; use HTTP by default for simpler queries.
Postgres.jsConst
node-postgresConst
serverless driverNeon’s serverless driver lets JavaScript and TypeScript applications query Postgres from serverless and edge runtimes over HTTP or WebSockets. Use neon() over HTTP by default, reserving Pool or Client for sessions, interactive transactions, or pg compatibility.
Compute unitsCompute Units (CUs) measure the size and processing capacity of a Neon compute. Each CU provides approximately 4 GB of RAM plus associated CPU and local SSD resources.
Autoscaling rangeAn autoscaling range defines the minimum and maximum Compute Units for a Neon compute. Neon scales within those bounds as workload changes, subject to an 8 CU maximum spread.
Suspend timeoutsuspend_timeout_seconds sets the inactivity delay before a Neon compute scales to zero. The default is 300 seconds; supported plans can customize it, disable suspension with -1, or use 0 for the plan default.
Primary branchIn current Neon terminology, “primary branch” is called the project’s default branch. It is the root branch created with each project and serves as the normal origin for new branches.
Default branchNeon’s default branch is the project’s designated branch for default workflows and implicit branch creation. It starts as the root branch, but you can move the designation to another existing branch.
Branch resetConst
Branch restoreConst
Schema-only branchA schema-only branch copies a source branch's database structure without its row data. It is useful for safe development and testing with sensitive datasets.
Database rolesNeon database roles are branch-scoped PostgreSQL roles used as login users or privilege groups. Roles created through Neon management interfaces receive neon_superuser membership; SQL-created roles require explicit permission grants.
SCRAM authenticationNeon supports SCRAM-SHA-256-PLUS through channel_binding=require. It binds mutual authentication to the TLS channel, helping protect connections from man-in-the-middle attacks.
Pooled endpoint portNeon’s pooled endpoint uses port 5432, the default PostgreSQL port. Choose it with a hostname ending in -pooler; the endpoint uses PgBouncer in transaction mode for high-concurrency workloads.
Direct endpointDATABASE_URL_UNPOOLED is Neon’s direct PostgreSQL connection string. Use it for migrations and other operations that require a non-pooled connection.
Allowed IPsConst
Project sharingProject sharing lets a project owner invite external Neon accounts to collaborate on one project through the Console, API, or CLI. It does not grant organization membership or project-deletion rights.
Organization billingNeon's organization Billing page in the Console centralizes charge review, payment details, invoices, plan changes, and billing support. Open it by selecting an organization from the profile menu and choosing Billing.
Usage metricsConst
Compute hoursCompute hours measure Neon compute usage. Calculate them by multiplying compute size in Compute Units by the number of active hours.
Data transferData transfer is Neon’s measure of traffic sent through the Neon proxy. It distinguishes public internet egress from bidirectional private-network transfer.
Storage GB-monthA GB-month is Neon’s unit for storage: one gigabyte retained for one month. Usage reflects both stored amount and retention time, so shorter retention produces proportionally fewer GB-months.
API keysNeon API keys are bearer tokens for authenticating Neon REST API requests. They come in personal, organization, and project-scoped forms; store the token securely because it is displayed only once.
Neon LocalNeon Local is a Docker proxy that exposes a local Postgres endpoint for a Neon cloud branch. It can target an existing branch or create and clean up an ephemeral branch automatically.
Vercel PostgresNeon's serverless driver replaces the Vercel Postgres SDK with a client for serverless and edge applications. Its HTTP API handles one-shot queries, while WebSocket-based classes support sessions and interactive transactions.
Cloudflare HyperdriveCloudflare Hyperdrive connects Cloudflare Workers to Neon Postgres through a globally distributed connection pool. It lets Workers use standard PostgreSQL drivers while reducing connection setup latency.
Drizzle KitDrizzle Kit is the CLI companion used with Drizzle ORM to manage schema migrations for a Neon Postgres database. Configure it in drizzle.config.ts, generate migration SQL, and apply those migrations with the CLI.
Prisma migrateNeon’s Prisma Migrate workflow uses a pooled connection for application runtime and a direct connection for Prisma CLI schema changes. Generate and test migrations with migrate dev; apply committed migrations in production with migrate deploy.
Logical replication publicationConst
SubscriberIn Neon logical replication, a subscriber is the destination database or platform that receives an initial data copy from a publisher and then ongoing row-level changes through a subscription.
Read-only computeA read-only compute is an independent Neon compute for read operations against the same storage used by a primary read-write compute. It adds read capacity without duplicating database storage.
Anonymized branchCreates a Neon branch containing statically masked data through PostgreSQL Anonymizer. Optional masking rules and automatic anonymization can be supplied in the same request.
Branch protectionNeon branch protection safeguards critical branches such as production from deletion, reset, project deletion, compute deletion, and inactivity archiving. It also generates fresh Postgres role passwords for child branches and can work with IP Allow restrictions.
Autosuspend delayConst
Connection string pooledA pooled Neon connection string routes through PgBouncer and has -pooler in its hostname. Use it by default for serverless applications and high-concurrency workloads.
Connection string directA direct Neon connection string connects straight to Postgres without the pooler. In the Connect modal, disable Connection pooling to obtain it; use it for migrations, pg_dump, and LISTEN/NOTIFY.

Module

NameWhat it does
sql queryModule
sql.querysql.query() runs manually parameterized SQL through Neon's serverless driver. Supply SQL with PostgreSQL placeholders and a separate values array to execute a query without interpolating values into the statement.
pool.queryModule
pool.connectModule
client.queryclient.query executes parameterized SQL through Neon’s serverless driver. Use sql.query for conventional SQL strings with $1-style placeholders; the HTTP driver is designed for single queries and non-interactive transactions.
client.connectModule
client.endModule
client.transactionsql.transaction() executes multiple queries together in one non-interactive transaction. It accepts an array of queries or a synchronous query-producing function, with optional transaction settings.
sql.transactionsql.transaction() executes multiple tagged SQL queries in one non-interactive transaction over the Neon serverless driver. Supply an array or a query-producing function, with optional transaction settings as the second argument.
sql.unsafesql.unsafe() embeds a trusted raw SQL string in a Neon tagged-template query. Use it for validated identifiers such as table or column names, never for untrusted input.
Pool.endPool.end() closes a Neon serverless driver's WebSocket pool after its work is complete. Await it during cleanup, especially when the pool is created within a request handler.
Client.endClient.end() closes a Neon serverless driver's Client connection. Call it during cleanup after WebSocket-based queries, sessions, or interactive transactions finish.

Pipe

NameWhat it does
webSocketConstructorneonConfig.webSocketConstructor configures the WebSocket implementation used by Neon’s serverless driver. Set it before constructing a WebSocket-based Pool or Client when the runtime lacks a built-in WebSocket.
poolQueryViaFetchPipe
fetchEndpointPipe
useSecureWebSocketPipe
wsProxywsProxy configures the WebSocket proxy endpoint used by Neon’s serverless driver. A callback can transform the target database host into a proxy URL, which is useful for local Postgres and host-specific routing.

Command

NameWhat it does
neonctl projectsneonctl projects is the Neon CLI command group for managing projects. Use neonctl projects list to view projects, with related subcommands for creating, updating, and deleting them.
neonctl branches createCreates a Neon branch for isolated development or testing. It defaults to the project's default branch and a read-write compute, with options for naming, parenting, expiration, protection, and compute sizing.
neonctl connection-stringCommand
neonctl databasesLists the databases belonging to a specified Neon branch. The operation is read-only and returns the branch's database collection.
neonctl rolesNeon CLI’s roles command group manages Postgres roles. It provides subcommands to create, delete, and list roles, and neonctl is an alias for neon.
neonctl authAuthenticates the Neon CLI through a browser, which is the recommended interactive method. A personal API key is the documented alternative for non-interactive use.
neonctl meCommand
neonctl operationsneonctl operations list lists operations for a Neon project. The command group also accepts the operation alias.
neonctl projects createCommand
neonctl branches listLists branches in a Neon project. It supports optional project selection and richer JSON output in addition to the default table format.
neonctl branches deletePermanently deletes a Neon project branch by ID or name. Specify --project-id unless a default project has been set with neon set-context.
neonctl databases createCommand
neonctl roles createCreates a PostgreSQL role in a Neon project from the command line. Provide a name and optionally select the branch, project, and whether the role can log in.
neonctl set-contextSaves Neon project, organization, and optionally branch context for later CLI commands. Use a default .neon file or select a named context file with --context-file.
neonctl ip-allowManage a Neon project's IP allowlist from the CLI. List, add, remove, or reset individual IPs, ranges, and CIDR entries, with optional protected-branch-only scope.

Search across every package and filter by type in your dashboard.

Start learning