0

Create a compute endpoint

by
Published Apr 8, 2025

Creates a compute endpoint for the specified branch.

Script neondb Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Neondb = {
3
	apiKey: string
4
}
5
/**
6
 * Create a compute endpoint
7
 * Creates a compute endpoint for the specified branch.
8
 */
9
export async function main(
10
	auth: Neondb,
11
	project_id: string,
12
	body: {
13
		endpoint: {
14
			branch_id: string
15
			region_id?: string
16
			type: 'read_only' | 'read_write'
17
			settings?: { pg_settings?: {}; pgbouncer_settings?: {} }
18
			autoscaling_limit_min_cu?: number
19
			autoscaling_limit_max_cu?: number
20
			provisioner?: string
21
			pooler_enabled?: false | true
22
			pooler_mode?: 'transaction'
23
			disabled?: false | true
24
			passwordless_access?: false | true
25
			suspend_timeout_seconds?: number
26
		}
27
	}
28
) {
29
	const url = new URL(`https://console.neon.tech/api/v2/projects/${project_id}/endpoints`)
30

31
	const response = await fetch(url, {
32
		method: 'POST',
33
		headers: {
34
			'Content-Type': 'application/json',
35
			Authorization: 'Bearer ' + auth.apiKey
36
		},
37
		body: JSON.stringify(body)
38
	})
39
	if (!response.ok) {
40
		const text = await response.text()
41
		throw new Error(`${response.status} ${text}`)
42
	}
43
	return await response.json()
44
}
45