0

Create a deployment

by
Published Oct 17, 2025

Create a new deployment: Example cURL request: ```console curl -s \ -X POST \ -H "Authorization: Bearer $REPLICATE_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "name": "my-app-image-generator", "model": "stability-ai/sdxl", "version": "da77bc59ee60423279fd632efb4795ab731d9e3ca9705ef3341091fb989b7eaf", "hardware": "gpu-t4", "min_instances": 0, "max_instances": 3 }' \ https://api.

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 deployment
7
 * Create a new deployment:
8

9
Example cURL request:
10

11
```console
12
curl -s \
13
  -X POST \
14
  -H "Authorization: Bearer $REPLICATE_API_TOKEN" \
15
  -H "Content-Type: application/json" \
16
  -d '{
17
        "name": "my-app-image-generator",
18
        "model": "stability-ai/sdxl",
19
        "version": "da77bc59ee60423279fd632efb4795ab731d9e3ca9705ef3341091fb989b7eaf",
20
        "hardware": "gpu-t4",
21
        "min_instances": 0,
22
        "max_instances": 3
23
      }' \
24
  https://api.
25
 */
26
export async function main(
27
  auth: Replicate,
28
  body: {
29
    hardware: string;
30
    max_instances: number;
31
    min_instances: number;
32
    model: string;
33
    name: string;
34
    version: string;
35
  },
36
) {
37
  const url = new URL(`https://api.replicate.com/v1/deployments`);
38

39
  const response = await fetch(url, {
40
    method: "POST",
41
    headers: {
42
      "Content-Type": "application/json",
43
      Authorization: "Bearer " + auth.token,
44
    },
45
    body: JSON.stringify(body),
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53