0

Get memory limit

by
Published Oct 17, 2025

Get the memory limit for one or more resources.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * Get memory limit
7
 * Get the memory limit for one or more resources.
8

9
 */
10
export async function main(
11
	auth: Render,
12
	startTime: string | undefined,
13
	endTime: string | undefined,
14
	resolutionSeconds: string | undefined,
15
	resource: string | undefined,
16
	service: string | undefined,
17
	instance: string | undefined
18
) {
19
	const url = new URL(`https://api.render.com/v1/metrics/memory-limit`)
20
	for (const [k, v] of [
21
		['startTime', startTime],
22
		['endTime', endTime],
23
		['resolutionSeconds', resolutionSeconds],
24
		['resource', resource],
25
		['service', service],
26
		['instance', instance]
27
	]) {
28
		if (v !== undefined && v !== '' && k !== undefined) {
29
			url.searchParams.append(k, v)
30
		}
31
	}
32
	const response = await fetch(url, {
33
		method: 'GET',
34
		headers: {
35
			Authorization: 'Bearer ' + auth.apiKey
36
		},
37
		body: undefined
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