Updated on 2025-12-10 GMT+08:00

Changing the ECS Billing Mode

Function

This API is used to change the ECS billing mode.

Constraints

  • This API can only be used to change the billing mode from pay-per-use to yearly/monthly.
  • You can batch change the billing modes of a maximum of 10 ECSs.
  • The EIP bound to the ECS whose billing mode is to be changed must be exclusive and billed by bandwidth.
  • The billing modes of ECSs that have shared EVS disks, DSS disks, or DESS disks attached cannot be changed.
  • If you want to use a coupon, set auto_pay in prepaid_options to false and pay for the product by referring to Paying Yearly/Monthly Product Orders, or use the coupon to pay for the product on the console.
  • The billing modes of ECSs on Dedicated Hosts (DeHs), Dedicated Clouds (DeCs), and edge clouds cannot be changed.
  • The billing modes of spot ECSs cannot be changed.

Debugging

You can debug this API in API Explorer.

Authorization

Each account has all of the permissions required to call all APIs, but IAM users must have the required permissions specifically assigned.
  • If you are using role/policy-based authorization, see the required permissions in Permissions and Supported Actions.
  • If you are using identity policy-based authorization, the permissions listed below are required.

Action

Access Level

Resource Type (*: required)

Condition Key

Alias

Dependencies

ecs:cloudServers:changeChargeMode

write

instance *

-

-

  • billing:order:pay
  • billing:subscription:renew

URI

POST /v1/{project_id}/cloudservers/actions/change-charge-mode

Table 1 describes the parameters in the URI.
Table 1 Parameter description

Parameter

Mandatory

Description

project_id

Yes

Specifies the project ID.

For details about how to obtain the ID, see Obtaining a Project ID.

Request

Table 2 Request parameters

Parameter

Mandatory

Type

Description

server_ids

Yes

Array of String

Definition

Specifies the IDs of ECSs whose billing modes are to be changed from pay-per-use to yearly/monthly.

Constraints

N/A

Range

N/A

Default Value

N/A

charge_mode

Yes

String

Definition

Specifies the new billing mode.

Constraints

N/A

Range

prePaid: Change the billing mode to yearly/monthly.

Default Value

N/A

prepaid_options

No

Object

Definition

Specifies the yearly/monthly billing mode. This parameter is mandatory when charge_mode is set to prePaid.

For details, see Table 3.

Constraints

N/A

Range

N/A

Default Value

N/A

dry_run

No

Boolean

Definition

Specifies whether to check the request. If this parameter is set to true, no instance is created.

Constraints

N/A

Range

  • true: Check the request. Check items include the mandatory parameters and request format.
    • If the check fails, the system returns an error.
    • If the check is successful, the system returns status code 202.
  • false: Send the request without checking the request body.

Default Value

false

Table 3 prepaid_options field description

Parameter

Mandatory

Type

Description

include_data_disks

No

Boolean

Definition

Specifies whether to change the billing modes of all pay-per-use data disks to yearly/monthly.

Constraints

The billing modes of ECSs that have shared EVS disks, DSS disks, or DESS disks attached cannot be changed.

Range

  • true: The billing modes of all pay-per-use data disks (including non-shared EVS disks) are changed to yearly/monthly.
  • false: The billing modes of all pay-per-use data disks are not changed to yearly/monthly.

Default Value

false

include_publicips

No

Boolean

Definition

Specifies whether to change the billing modes of EIPs that are exclusive and billed by bandwidth to yearly/monthly.

After the EIPs are changed to yearly/monthly, they can be unbound or deleted separately.

Constraints

N/A

Range

  • true: The billing modes of the EIPs are changed to yearly/monthly.
  • false: The billing modes of the EIPs are not changed to yearly/monthly.

Default Value

false

period_type

Yes

String

Definition

Specifies the subscription period.

Constraints

N/A

Range

  • month: indicates that the subscription period is month.
  • year: indicates that the subscription period is year.

Default Value

N/A

period_num

Yes

String

Definition

Specifies the number of subscription periods.

Constraints

N/A

Range

  • When period_type is set to month, the value range is from 1 to 9.
  • When period_type is set to year, the value range is from 1 to 3.

Default Value

N/A

auto_pay

No

Boolean

Definition

Specifies whether to enable automatic payment.

Constraints

N/A

Range

  • true: Automatic payment is enabled. Ensure that the account balance is sufficient, or abnormal orders are generated and the original orders are discarded.
  • false: Orders are generated and no fees are deducted.

Default Value

false

auto_renew

No

Boolean

Definition

Specifies whether to enable auto-renewal.

Constraints

N/A

Range

  • true: Auto-renewal is enabled.
  • false: Auto-renewal is disabled.

Default Value

false

Response

Table 4 Parameter description

Parameter

Type

Description

order_id

String

Specifies the ID of the order for changing the billing mode to yearly/monthly.

Example Request

Change the billing mode of an ECS and the exclusive EIP billed by bandwidth to yearly/monthly with the subscription period set to one month.

POST https://{endpoint}/v1/{project_id}/cloudservers/actions/change-charge-mode

{
    "server_ids": [
        "f631ee2c-1caf-4c4f-9cee-f3181b8e44ad"
    ],
    "charge_mode": "prePaid",
    "prepaid_options": {
        "include_publicips": true,
        "include_data_disks": false,
        "period_type": "month",
        "period_num": "1",
        "auto_pay": false,
        "auto_renew": false
    },
    "dry_run": false
}

Example Response

{
    order_id: "CS2102041657OL0EY"
}

Error Codes

See Error Codes.