List all files you have in openAI
1
type Openai = {
2
api_key: string,
3
organization_id: string
4
5
}
6
7
export async function main(
8
openAI: Openai
9
) {
10
const res = await fetch("https://api.openai.com/v1/files", {
11
headers: {
12
"Authorization": "Bearer " + openAI.api_key
13
14
})
15
16
if (!res.ok) {
17
let err = await res.text()
18
19
throw new Error(err)
20
21
22
// this is prop going to be json 100% of the time, but lets just do the test
23
if (res.headers.get("Content-Type")?.includes("json")) {
24
return await res.json()
25
26
return await res.text()
27
28