1 |
|
2 | type Ai21 = { |
3 | apiKey: string; |
4 | }; |
5 |
|
6 | * Create Route |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Ai21, |
11 | assistant_id: string, |
12 | body: { |
13 | plan_id: string; |
14 | name: string; |
15 | description: string; |
16 | examples: string[]; |
17 | }, |
18 | ) { |
19 | const url = new URL( |
20 | `https://api.ai21.com/studio/v1/assistants/${assistant_id}/routes`, |
21 | ); |
22 |
|
23 | const response = await fetch(url, { |
24 | method: "POST", |
25 | headers: { |
26 | "Content-Type": "application/json", |
27 | Authorization: "Bearer " + auth.apiKey, |
28 | }, |
29 | body: JSON.stringify(body), |
30 | }); |
31 | if (!response.ok) { |
32 | const text = await response.text(); |
33 | throw new Error(`${response.status} ${text}`); |
34 | } |
35 | return await response.json(); |
36 | } |
37 |
|