0

Create a model

by
Published Oct 17, 2025

Create a model.

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 model
7
 * Create a model.
8
 */
9
export async function main(
10
  auth: Replicate,
11
  body: {
12
    cover_image_url?: string;
13
    description?: string;
14
    github_url?: string;
15
    hardware: string;
16
    license_url?: string;
17
    name: string;
18
    owner: string;
19
    paper_url?: string;
20
    visibility: "public" | "private";
21
  },
22
) {
23
  const url = new URL(`https://api.replicate.com/v1/models`);
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.text();
38
}
39