0

Create a training

by
Published Oct 17, 2025

Start a new training of the model version you specify.

Script replicate Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Replicate = {
3
  token: string;
4
};
5
/**
6
 * Create a training
7
 * Start a new training of the model version you specify.
8
 */
9
export async function main(
10
  auth: Replicate,
11
  model_owner: string,
12
  model_name: string,
13
  version_id: string,
14
  body: {
15
    destination: string;
16
    input: {};
17
    webhook?: string;
18
    webhook_events_filter?: "start" | "output" | "logs" | "completed"[];
19
  },
20
) {
21
  const url = new URL(
22
    `https://api.replicate.com/v1/models/${model_owner}/${model_name}/versions/${version_id}/trainings`,
23
  );
24

25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39