Cancels a run that is in_progress.
in_progress
1
type Openai = {
2
api_key: string;
3
organization_id: string;
4
};
5
/**
6
* Cancel run
7
* Cancels a run that is `in_progress`.
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}/cancel`
12
);
13
14
const response = await fetch(url, {
15
method: "POST",
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