0

Update service auto scaling settings

by
Published Oct 17, 2025

Updates minimum and maximum memory limits per replica and idle mode scaling behavior for the service. The memory settings are available only for "production" services and must be a multiple of 4 starting from 8GB. Please contact support to enable adjustment of numReplicas.

Script clickhouse Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Clickhouse = {
3
  username: string;
4
  password: string;
5
  host: string;
6
};
7
/**
8
 * Update service auto scaling settings
9
 * Updates minimum and maximum memory limits per replica and idle mode scaling behavior for the service. The memory settings are available only for "production" services and must be a multiple of 4 starting from 8GB. Please contact support to enable adjustment of numReplicas.
10
 */
11
export async function main(
12
  auth: Clickhouse,
13
  organizationId: string,
14
  serviceId: string,
15
  body: {
16
    minReplicaMemoryGb?: number;
17
    maxReplicaMemoryGb?: number;
18
    numReplicas?: number;
19
    idleScaling?: false | true;
20
    idleTimeoutMinutes?: number;
21
  }
22
) {
23
  const url = new URL(
24
    `https://api.clickhouse.cloud/v1/organizations/${organizationId}/services/${serviceId}/replicaScaling`
25
  );
26

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