type Openai = {
api_key: string,
organization_id: string
}
export async function main(
openAI: Openai
) {
const res = await fetch("https://api.openai.com/v1/files", {
headers: {
"Authorization": "Bearer " + openAI.api_key
}
})
if (!res.ok) {
let err = await res.text()
throw new Error(err)
}
// this is prop going to be json 100% of the time, but lets just do the test
if (res.headers.get("Content-Type")?.includes("json")) {
return await res.json()
}
return await res.text()
}
Submitted by sindre svendby964 1000 days ago