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

Retrieve a message.

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

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