0

Create service preview (image-backed)

by
Published Oct 17, 2025

Create a preview instance for an image-backed service. The preview uses the settings of the base service (referenced by `serviceId`), except settings overridden via provided parameters. View all active previews from your service's Previews tab in the Render Dashboard. Note that you can't create previews for Git-backed services using the Render API.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * Create service preview (image-backed)
7
 * Create a preview instance for an image-backed service. The preview uses the settings of the base service (referenced by `serviceId`), except settings overridden via provided parameters.
8

9
View all active previews from your service's Previews tab in the Render Dashboard.
10

11
Note that you can't create previews for Git-backed services using the Render API.
12

13
 */
14
export async function main(
15
	auth: Render,
16
	serviceId: string,
17
	body: {
18
		imagePath: string
19
		name?: string
20
		plan?:
21
			| 'starter'
22
			| 'starter_plus'
23
			| 'standard'
24
			| 'standard_plus'
25
			| 'pro'
26
			| 'pro_plus'
27
			| 'pro_max'
28
			| 'pro_ultra'
29
			| 'free'
30
			| 'custom'
31
	}
32
) {
33
	const url = new URL(`https://api.render.com/v1/services/${serviceId}/preview`)
34

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