Modify run

Modifies a run.

Script openai Verified

by hugo697 ยท 12/1/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 372 days ago
1
type Openai = {
2
  api_key: string;
3
  organization_id: string;
4
};
5
/**
6
 * Modify run
7
 * Modifies a run.
8
 */
9
export async function main(
10
  auth: Openai,
11
  thread_id: string,
12
  run_id: string,
13
  body: { metadata?: { [k: string]: unknown } }
14
) {
15
  const url = new URL(
16
    `https://api.openai.com/v1/threads/${thread_id}/runs/${run_id}`
17
  );
18

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