0

Create a new client key

by
Published Oct 17, 2025

Create a new client key bound to a project. The key's secret and public key are generated by the server.

Script sentry Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Create a new client key
4
 * Create a new client key bound to a project.  The key's secret and public key
5
are generated by the server.
6
 */
7
export async function main(auth: RT.Sentry, project_id_or_slug: string, body: Body) {
8
	const url = new URL(
9
		`https://${auth.region}.sentry.io/api/0/projects/${auth.organizationSlug}/${project_id_or_slug}/keys/`
10
	)
11

12
	const response = await fetch(url, {
13
		method: 'POST',
14
		headers: {
15
			'Content-Type': 'application/json',
16
			Authorization: 'Bearer ' + auth.token
17
		},
18
		body: JSON.stringify(body)
19
	})
20
	if (!response.ok) {
21
		const text = await response.text()
22
		throw new Error(`${response.status} ${text}`)
23
	}
24
	return await response.json()
25
}
26

27
/* eslint-disable */
28
/**
29
 * This file was automatically generated by json-schema-to-typescript.
30
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
31
 * and run json-schema-to-typescript to regenerate this file.
32
 */
33

34
export interface Body {
35
	/**
36
	 * The optional name of the key. If not provided it will be automatically generated.
37
	 */
38
	name?: string
39
	/**
40
	 * Applies a rate limit to cap the number of errors accepted during a given time window. To
41
	 * disable entirely set `rateLimit` to null.
42
	 * ```json
43
	 * {
44
	 *     "rateLimit": {
45
	 *         "window": 7200, // time in seconds
46
	 *         "count": 1000 // error cap
47
	 *     }
48
	 * }
49
	 * ```
50
	 */
51
	rateLimit?: {
52
		count?: number
53
		window?: number
54
		[k: string]: unknown
55
	}
56
	/**
57
	 * * `user`
58
	 * * `profiling`
59
	 * * `escalating_issues`
60
	 * * `tempest`
61
	 * * `demo`
62
	 */
63
	useCase?: 'user' | 'profiling' | 'escalating_issues' | 'tempest' | 'demo'
64
	[k: string]: unknown
65
}
66