Help Center/ ModelArts/ API Reference/ Model Inference/ HPA Policy/ Creating an Auto Scaling Policy
Updated on 2026-07-24 GMT+08:00

Creating an Auto Scaling Policy

Function

This API is used to create a scheduled scaling policy for a deployed service. It is applicable to scenarios where the number of service instances needs to be automatically adjusted based on the service load or at a specified time. Before calling this API, ensure that the service has been deployed, a valid service ID has been obtained, and detailed scaling policy parameters, such as the scaling time, instance quantity range, and condition trigger, have been provided. After the creation, the system automatically adjusts the number of service instances based on the preset policy. This ensures the performance and availability of the service within the specified period. If the provided service ID is invalid, the parameter settings are incorrect, or the system resources are insufficient, an error message is displayed, prompting you to check the validity of the input data or contact technical support.

Debugging

You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.

  • If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependencies

    modelarts:service:createHpa

    Read

    service *

    -

    -

    -

URI

POST /v2/{project_id}/services/{service_id}/deployments/{deployment_id}/hpa

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition

Project ID. For details, see Obtaining a Project ID and Name.

Constraints

N/A

Range

Project ID.

Default Value

N/A

service_id

Yes

String

Definition: Service ID, which can be obtained from the response body during service creation or by querying the service list. The service_id field indicates the service ID.

Constraints

N/A

Range

Service ID.

Default Value

N/A

deployment_id

Yes

String

Definition

Deployment ID, which you can obtain from the response body when adding the deployment or by obtaining service deployments. The deployment_id field indicates the deployment ID.

Constraints

N/A

Range

Deployment ID.

Default Value

N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition

User token. It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token. For details about how to obtain the token, see Obtaining a User Token Through Password Authentication.

Constraints

N/A

Range

N/A

Default Value

N/A

Content-Type

Yes

String

Definition

Message body type or format.

Constraints

N/A

Range

  • application/json

  • application/json;charset=utf-8

Default Value

N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

type

Yes

String

Definition

Auto scaling type.

Range

  • CRON_HPA: scheduled scaling policy

  • METRIC_HPA: metric-based scaling policy

Constraints

N/A

Default Value

N/A

target_resource_id

Yes

String

Definition

ID of the target to which the auto scaling policy is bound.

Range

Instance group ID.

Constraints

N/A

Default Value

N/A

target_resource_type

Yes

String

Definition

Type of the target to which the auto scaling policy is bound.

Range

  • GROUP: instance group

Constraints

N/A

Default Value

N/A

hpa_rules

Yes

Array of HpaRules objects

Definition

Auto scaling rule.

Constraints

N/A

workspace_id

No

String

Definition

Workspace ID.

Range

  • 0: default workspace ID

  • 32 characters consisting of digits and lowercase letters. For details about other space IDs, see Creating a Workspace.

Constraints

N/A

Default Value

N/A

Table 4 HpaRules

Parameter

Mandatory

Type

Description

name

No

String

Definition

Auto scaling rule name.

Range

The value contains 4 to 64 characters, including lowercase letters, digits, and hyphens (-). The value must start with a lowercase letter and cannot end with a hyphen (-).

Constraints

N/A

Default Value

N/A

id

No

String

Definition

Auto scaling ID.

Range

The value can contain 4 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.

Constraints

N/A

Default Value

N/A

disable

No

Boolean

Definition

Specifies whether to enable the auto scaling rule.

Range

  • false: enabled

  • true: disabled

Constraints

N/A

Default Value

N/A

type

Yes

String

Definition

Auto scaling type.

Range

  • CRON_HPA: scheduled scaling policy

  • METRIC_HPA: metric-based scaling policy

Constraints

N/A

Default Value

N/A

status

No

String

Definition

Auto scaling type.

Range

  • CREATING: The scaling policy is being created.

  • CONFIG_SUCCESS: The scaling policy is configured.

  • EXECUTE_SUCCESS: The scaling policy is executed.

  • DELETED: The scaling policy is deleted.

  • FAILED: The scaling policy failed.

Constraints

N/A

Default Value

N/A

operate

No

String

Definition

Auto scaling type.

Range

  • ADD: Add a scaling policy rule.

  • UPDATE: Modify a scaling policy rule.

  • DELETE: Delete a scaling policy rule.

Constraints

N/A

Default Value

N/A

schedule

Yes

String

Definition

Cron expression for executing scheduled auto scaling. The value starts at a minute level and does not support seconds.

Range

N/A

Constraints

N/A

Default Value

N/A

target_replicas

Yes

Integer

Definition

Number of target instances for auto scaling.

Range

The value ranges from 1 to 128. The API can receive floating-point numbers, and the backend automatically rounds down the number.

Constraints

N/A

Default Value

N/A

min_replicas

No

Integer

Definition

Minimum number of instances for auto scaling.

Range

The value ranges from 1 to 128. The API can receive floating-point numbers, and the backend automatically rounds down the number.

Constraints

N/A

Default Value

N/A

max_replicas

No

Integer

Definition

Maximum number of instances for auto scaling.

Range

The value ranges from 1 to 128. The API can receive floating-point numbers, and the backend automatically rounds down the number.

Constraints

N/A

Default Value

N/A

downscale_window

No

Integer

Definition

Cooldown period for auto scale-out.

Range

The value ranges from 1 to 128. The API can receive floating-point numbers, and the backend automatically rounds down the number.

Constraints

N/A

Default Value

N/A

upscale_window

No

Integer

Definition

Cooldown period for auto scale-in.

Range

The value ranges from 1 to 128. The API can receive floating-point numbers, and the backend automatically rounds down the number.

Constraints

N/A

Default Value

N/A

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

id

String

Definition

Auto scaling policy ID.

Range

N/A

name

String

Definition

Name of an auto scaling policy.

Range

N/A

target_resource_id

String

Definition

ID of the target to which the auto scaling policy is bound.

Range

Instance group ID.

target_resource_type

String

Definition

Type of the target to which the auto scaling policy is bound.

Range

  • GROUP: instance group

min_replicas

Integer

Definition

Minimum number of instances for auto scaling.

Range

1-128

max_replicas

Integer

Definition

Maximum number of instances for auto scaling.

Range

1-128

status

String

Definition

Status of the auto scaling policy.

Range

  • INACTIVE: disabled

  • ACTIVE: enabled

  • DELETED

workspace_id

String

Definition

Workspace ID.

Range

  • 0: default workspace ID

  • 32 characters consisting of digits and lowercase letters. For details about other space IDs, see Creating a Workspace.

hpa_rules

Array of HpaRule objects

Definition

Auto scaling rules.

Table 6 HpaRule

Parameter

Type

Description

id

String

Definition

Auto scaling rule ID.

Range

N/A

hpa_id

String

Definition

ID of the policy associated with the auto scaling rule.

Range

N/A

name

String

Definition

Auto scaling rule name.

Range

The value can contain 4 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.

type

String

Definition

Auto scaling type.

Range

  • CRON_HPA: scheduled scaling policy

  • METRIC_HPA: metric-based scaling policy

schedule

String

Definition

Cron expression for executing scheduled auto scaling. The value starts at a minute level and does not support seconds.

Range

N/A

target_replicas

Integer

Definition

Number of target instances for auto scaling.

Range

1 to 128

disable

String

Definition

Specifies whether to enable the auto scaling rule.

Range

  • false

  • true

status

String

Definition

Status of the auto scaling rule.

Range

  • CREATING

  • CONFIG_SUCCESS

  • EXECUTE_SUCCESS

  • DELETED

  • FAILED

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

  • Definition: ModelArts error code.

Range: N/A.

error_msg

String

Definition: Error message.

Range: N/A.

Status code: 500

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

  • Definition: ModelArts error code.

Range: N/A.

error_msg

String

Definition: Error message.

Range: N/A.

Example Requests

Create a rule. This API is used when no rule exists in the service.

POST https://{end_point}/v2/{project_id}/services/{service_id}/deployments/{deployment_id}/hpa

{
  "type" : "CRON_HPA",
  "target_resource_id" : "8a927efb-2e23-42e5-92ea-de86b4aba750",
  "target_resource_type" : "GROUP",
  "hpa_rules" : [ {
    "name" : "test-rule1",
    "disable" : false,
    "type" : "CRON_HPA",
    "schedule" : "22 9 * * ?",
    "target_replicas" : 3
  }, {
    "name" : "test-rule2",
    "disable" : true,
    "type" : "CRON_HPA",
    "schedule" : "0 0 * * ?",
    "target_replicas" : 1
  } ]
}

Example Responses

Status code: 200

Response body for creating an auto scaling policy.

{
  "hpa_rules" : [ {
    "disable" : true,
    "hpa_id" : "8521e55e-219f-4769-8a2f-08a78c02182e",
    "id" : "accba651-d3fd-4434-8254-61d30e9e1b45",
    "name" : "test-rule2",
    "schedule" : "0 0 * * ?",
    "status" : "CREATING",
    "target_replicas" : 1,
    "type" : "CRON_HPA"
  }, {
    "disable" : false,
    "hpa_id" : "8521e55e-219f-4769-8a2f-08a78c02182e",
    "id" : "7447626f-6c94-4ad7-a527-d3fa04706788",
    "name" : "test-rule3",
    "schedule" : "38 10 * * ?",
    "status" : "CREATING",
    "target_replicas" : 3,
    "type" : "CRON_HPA"
  } ],
  "id" : "8521e55e-219f-4769-8a2f-08a78c02182e",
  "name" : "cron-hpa-8a927efb-2e23-42e5-92ea-de86b4aba750",
  "status" : "ACTIVE",
  "target_resource_id" : "8a927efb-2e23-42e5-92ea-de86b4aba750",
  "target_resource_type" : "GROUP"
}

Status Codes

Status Code

Description

200

Response body for creating an auto scaling policy.

400

Resource not found.

500

An exception occurs when the ModelArts OS API is called.

Error Codes

See Error Codes.