0

Openai Completions

by
Published Oct 17, 2025
Script deep_infra Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Deepinfra = {
3
  token: string;
4
};
5
/**
6
 * Openai Completions
7
 *
8
 */
9
export async function main(
10
  auth: Deepinfra,
11
  x_deepinfra_source: string,
12
  user_agent: string,
13
  body: {
14
    model: string;
15
    prompt: string;
16
    max_tokens?: number;
17
    temperature?: number;
18
    top_p?: number;
19
    min_p?: number;
20
    top_k?: number;
21
    n?: number;
22
    stream?: false | true;
23
    logprobs?: number;
24
    echo?: false | true;
25
    stop?: string | string[];
26
    presence_penalty?: number;
27
    frequency_penalty?: number;
28
    response_format?: { type?: "text" | "json_object" };
29
    repetition_penalty?: number;
30
    user?: string;
31
    seed?: number;
32
  },
33
) {
34
  const url = new URL(`https://api.deepinfra.com/v1/openai/completions`);
35

36
  const response = await fetch(url, {
37
    method: "POST",
38
    headers: {
39
      "x-deepinfra-source": x_deepinfra_source,
40
      "user-agent": user_agent,
41
      "Content-Type": "application/json",
42
      Authorization: "Bearer " + auth.token,
43
    },
44
    body: JSON.stringify(body),
45
  });
46
  if (!response.ok) {
47
    const text = await response.text();
48
    throw new Error(`${response.status} ${text}`);
49
  }
50
  return await response.json();
51
}
52