0

Revoke an API key

by
Published Apr 8, 2025

Revokes the specified API key. An API key that is no longer needed can be revoked. This action cannot be reversed. You can obtain `key_id` values by listing the API keys for your Neon account. API keys can also be managed in the Neon Console. See [Manage API keys](https://neon.tech/docs/manage/api-keys/).

Script neondb Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Neondb = {
3
	apiKey: string
4
}
5
/**
6
 * Revoke an API key
7
 * Revokes the specified API key.
8
An API key that is no longer needed can be revoked.
9
This action cannot be reversed.
10
You can obtain `key_id` values by listing the API keys for your Neon account.
11
API keys can also be managed in the Neon Console.
12
See [Manage API keys](https://neon.tech/docs/manage/api-keys/).
13

14
 */
15
export async function main(auth: Neondb, key_id: string) {
16
	const url = new URL(`https://console.neon.tech/api/v2/api_keys/${key_id}`)
17

18
	const response = await fetch(url, {
19
		method: 'DELETE',
20
		headers: {
21
			Authorization: 'Bearer ' + auth.apiKey
22
		},
23
		body: undefined
24
	})
25
	if (!response.ok) {
26
		const text = await response.text()
27
		throw new Error(`${response.status} ${text}`)
28
	}
29
	return await response.json()
30
}
31