0

Update an assistant

by
Published Apr 8, 2025

Update an AI Assistant's attributes.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Update an assistant
7
 * Update an AI Assistant's attributes.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	assistant_id: string,
12
	body: {
13
		name?: string
14
		model?: string
15
		description?: string
16
		instructions?: string
17
		tools?:
18
			| {
19
					type: 'function'
20
					function: { name: string; description?: string; parameters?: {} }
21
			  }
22
			| {
23
					type: 'retrieval'
24
					retrieval: { bucket_ids: string[]; max_num_results?: number }
25
			  }[]
26
	}
27
) {
28
	const url = new URL(`https://api.telnyx.com/v2/ai/assistants/${assistant_id}`)
29

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