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

Retrieves a run.

Created by hugo697 139 days ago Viewed 3975 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 139 days ago
1
type Openai = {
2
  api_key: string;
3
  organization_id: string;
4
};
5
/**
6
 * Get run
7
 * Retrieves a run.
8
 */
9
export async function main(auth: Openai, thread_id: string, run_id: string) {
10
  const url = new URL(
11
    `https://api.openai.com/v1/threads/${thread_id}/runs/${run_id}`
12
  );
13

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