0
Retrieve model
One script reply has been approved by the moderators Verified

Retrieves a model instance, providing basic information about the model such as the owner and permissioning.

Created by hugo697 137 days ago Viewed 3729 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 137 days ago
1
type Openai = {
2
  api_key: string;
3
  organization_id: string;
4
};
5
/**
6
 * Retrieve model
7
 * Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
8
 */
9
export async function main(auth: Openai, model: string) {
10
  const url = new URL(`https://api.openai.com/v1/models/${model}`);
11

12
  const response = await fetch(url, {
13
    method: "GET",
14
    headers: {
15
      "OpenAI-Organization": auth.organization_id,
16
      Authorization: "Bearer " + auth.api_key,
17
    },
18
    body: undefined,
19
  });
20
  if (!response.ok) {
21
    const text = await response.text();
22
    throw new Error(`${response.status} ${text}`);
23
  }
24
  return await response.json();
25
}
26