1
//native
2
type Deepinfra = {
3
token: string;
4
};
5
/**
6
* Create Openai Batch
7
*
8
*/
9
export async function main(
10
auth: Deepinfra,
11
body: {
12
input_file_id: string;
13
endpoint: "/v1/chat/completions" | "/v1/completions";
14
completion_window: "24h";
15
metadata?: {};
16
},
17
) {
18
const url = new URL(`https://api.deepinfra.com/v1/openai/batches`);
19
20
const response = await fetch(url, {
21
method: "POST",
22
headers: {
23
"Content-Type": "application/json",
24
Authorization: "Bearer " + auth.token,
25
26
body: JSON.stringify(body),
27
});
28
if (!response.ok) {
29
const text = await response.text();
30
throw new Error(`${response.status} ${text}`);
31
}
32
return await response.json();
33
34