0
Delete File
One script reply has been approved by the moderators Verified

Delete the specified file from the library.

Restrictions: Files in PROCESSING status cannot be deleted. Attempts to delete such files will result in a 422 error.

Created by hugo697 32 days ago Viewed 2803 times
0
Submitted by hugo697 Bun
Verified 32 days ago
1
//native
2
type Ai21 = {
3
  apiKey: string;
4
};
5
/**
6
 * Delete File
7
 * Delete the specified file from the library.
8

9
**Restrictions**:
10
Files in `PROCESSING` status cannot be deleted. Attempts to delete such files will result in a 422 error.
11
 */
12
export async function main(auth: Ai21, file_id: string) {
13
  const url = new URL(
14
    `https://api.ai21.com/studio/v1/library/files/${file_id}`,
15
  );
16

17
  const response = await fetch(url, {
18
    method: "DELETE",
19
    headers: {
20
      Authorization: "Bearer " + auth.apiKey,
21
    },
22
    body: undefined,
23
  });
24
  if (!response.ok) {
25
    const text = await response.text();
26
    throw new Error(`${response.status} ${text}`);
27
  }
28
  return await response.json();
29
}
30