0
Get message file
One script reply has been approved by the moderators Verified

Retrieves a message file.

Created by hugo697 239 days ago Viewed 8909 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 239 days ago
1
type Openai = {
2
  api_key: string;
3
  organization_id: string;
4
};
5
/**
6
 * Get message file
7
 * Retrieves a message file.
8
 */
9
export async function main(
10
  auth: Openai,
11
  thread_id: string,
12
  message_id: string,
13
  file_id: string
14
) {
15
  const url = new URL(
16
    `https://api.openai.com/v1/threads/${thread_id}/messages/${message_id}/files/${file_id}`
17
  );
18

19
  const response = await fetch(url, {
20
    method: "GET",
21
    headers: {
22
      "OpenAI-Organization": auth.organization_id,
23
      Authorization: "Bearer " + auth.api_key,
24
    },
25
    body: undefined,
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33