You can call this operation to change the billing method of ECS instances. You can change the billing method of instances between pay-as-you-go and subscription, or change the billing method of all data disks attached to an instance from pay-as-you-go to subscription.

Description

Before you call this operation, make sure that you have fully understood the billing methods and pricing schedule of ECS.

When you call this operation, take note of the following items:

  • The instance must be in the Running or Stopped state and has no overdue payment.
  • After you change the billing method, automatic payment is enabled by default. When your account balance is insufficient, your order will become invalid and you have to cancel this order. If your account balance is insufficient, to prevent your order from becoming invalid, you can set AutoPay to false. This ensures a normal order is generated. Then you can log on to the ECS console to pay for the order.
  • Switch of the billing method from subscription to pay-as-you-go:
    • Whether you can convert the billing method depends on your usage amount of ECS instances.
    • After you change the billing method from subscription to pay-as-you-go, the new billing method will take effect for the entire lifecycle of the instance. The price difference is refunded to the payment account you used. Price difference of coupon purchases are not refunded.
    • Refund rule: You can only use a certain amount of refund within a month, and the refund that is not used within the current month will not be accumulated to the next month. After you have used up the refund amount for the current month, you can only change the billing method when the next month arrives. The refund amount incurred when you change billing methods is calculated with the following formula: Number of vCPUs × (Number of remaining days × 24 ± Number of remaining or elapsed hours).
  • Switch of the billing method from pay-as-you-go to subscription:
    • You can change all pay-as-you-go data disks attached to an instance to subscription ones.
    • This operation cannot be called if the automatic release time has been set for the pay-as-you-go instance.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String No ModifyInstanceChargeType

The operation that you want to perform. For API requests using the HTTP and HTTPS methods, the Action parameter is required. Set the value to ModifyInstanceChargeType.

InstanceIds String Yes ["i-bp67acfmxazb4ph***","i-bp67acfmxazb4pi***"]

The ID of the instance. It can be an array in the JSON format that consists of instance IDs. Separate multiple instance IDs with commas (,). A maximum of 20 instance IDs can be entered at a time.

RegionId String Yes cn-hangzhou

The region ID of the instance. You can call the DescribeRegions operation to query the most recent region list.

Period Integer No 1

The renewal period of the subscription instance. If the ECS instance is hosted on a dedicated host, the renewal period of the ECS instance cannot exceed the subscription period of the dedicated host. Valid values:

  • If PeriodUnit=Month, the valid values of Period are 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 24, 36, 48, and 60.
PeriodUnit String No Month

The unit of the Period parameter. Default value: month. Valid values:

  • Month
IncludeDataDisks Boolean No true

Specifies whether to change all pay-as-you-go data disks attached to the instance to subscription ones.

Default value: true.

DryRun Boolean No false

Specifies whether to check the request only. Default value: false. Valid values:

  • true: sends the check request without querying the resource status. The system checks whether your AccessKey pair is valid, whether RAM users are authorized, and whether required parameters are specified. If the check fails, the corresponding error code is returned. If the check succeeds, the DryRunOperation error code is returned.
  • false: The request is checked, and a 2XX HTTP status code is returned and resources are queried if the check succeeds.
AutoPay Boolean No false

Specifies whether payment is automatically made. Default value: true. Valid values:

  • true: automatically charges fees. When your account balance is insufficient, your order will become invalid and you have to cancel this order.
  • false: generates an order but does not charge fees.
Note If your account balance is insufficient, to prevent your order becomes invalid, you can set the AutoPay parameter to false. This ensure a normal order is generated. Then you can log on to the ECS console to pay for the order.
InstanceChargeType String No PrePaid

The new billing method. Default value: PrePaid. Valid values:

  • PrePaid: changes the billing method from pay-as-you-go to subscription.
  • PostPaid: changes the billing method from subscription to pay-as-you-go.
ClientToken String No 123e4567-e89b-12d3-a456-426655440000

The client token that is used to ensure the idempotence of the request. You can use the client to generate the value, but you must ensure that it is unique among different requests. The ClientToken parameter can only contain ASCII characters and cannot exceed 64 characters in length. For more information, see How to ensure idempotence.

IsDetailFee Boolean No false

Specifies whether to return cost details of the order when the billing method is changed from subscription to pay-as-you-go.

Default value: false.

Response parameters

Parameter Type Example Description
RequestId String B61C08E5-403A-46A2-96C1-F7B1216DB10C

The ID of the request.

OrderId String 204135153880***

The ID of the generated order.

FeeOfInstances Array

The cost details of the order.

InstanceId String i-bp67acfmxazb4ph***

The ID of the instance.

Fee String 0

The cost value.

Currency String CNY

The unit of currency for the bill.

Examples

Sample requests

https://ecs.aliyuncs.com/?Action=ModifyInstanceChargeType
&RegionId=cn-hangzhou
&InstanceIds=["i-bp67acfmxazb4ph***","i-bp67acfmxazb4pi***"]
&Period=1
&PeriodUnit=Month
&AutoPay=false
&IncludeAllDisks=true
&ClientToken=123e4567-e89b-12d3-a456-426655440000
&<Common request parameters>

Sample success responses

XML format

<ModifyInstanceChargeTypeResponse>
      <RequestId>B61C08E5-403A-46A2-96C1-F7B1216DB10C</RequestId>
      <OrderId>204135153880***</OrderId>
      <FeeOfInstances>
            <FeeOfInstance>
                  <Fee>0</Fee>
                  <InstanceId>i-bp67acfmxazb4ph***</InstanceId>
                  <Currency>CNY</Currency>
            </FeeOfInstance>
            <FeeOfInstance>
                  <Fee>0</Fee>
                  <InstanceId>i-bp67acfmxazb4pi***</InstanceId>
                  <Currency>CNY</Currency>
            </FeeOfInstance>
      </FeeOfInstances>
</ModifyInstanceChargeTypeResponse>

JSON format

{
    "RequestId":"B61C08E5-403A-46A2-96C1-F7B1216DB10C",
    "OrderId":"204135153880***",
    "FeeOfInstances":
    {
        "FeeOfInstance":[
            {
                "Fee":"0",
                "InstanceId":"i-bp67acfmxazb4ph***",
                "Currency":"CNY"
            },
            {
                "Fee":"0",
                "InstanceId":"i-bp67acfmxazb4pi***",
                "Currency":"CNY"
            }
        ]
    }
}

Error codes

HTTP status code Error code Error message Description
400 InvalidParameter.InstanceIds The specified InstanceIds are invalid. The error message returned because the specified instance is invalid.
400 InvalidParameter %s The error message returned because the specified parameter is invalid.
400 InvalidStatus.ValueNotSupported %s The error message returned because the operation is not supported while the resource is in the current state.
400 InvalidInstanceChargeType.ValueNotSupported %s The error message returned because the charge type is not supported. Check related information and try again.
400 ExpiredInstance The specified instance has expired. The error message returned because the specified instance has expired.
403 InvalidInstance.TempBandwidthUpgrade Cannot switch to Pay-As-You-Go during the period of temporary bandwidth upgrade. The error message returned because you change the billing method to pay-as-you-go during temporary bandwidth upgrade.
400 InstancesIdQuotaExceed The maximum number of Instances is exceeded. The error message returned because the maximum number of instances has been reached.
400 InvalidClientToken.ValueNotSupported The ClientToken provided is invalid. The error message returned because the specified value of the ClientToken parameter is invalid.
400 InvalidInternetChargeType.ValueNotSupported %s The error message returned because the specified charge type is not supported. Check whether the parameter is correct.
403 InvalidInstanceType.ValueNotSupported The specified InstanceType does not exist or beyond the permitted range. The error message returned because the specified instance type does not exist or you are not authorized to operate on the instance type.
403 InstanceType.Offline %s The error message returned because the instance type is phased-out or instances of this instance type are insufficient.
500 InternalError The request processing has failed due to some unknown error, exception or failure. The error message returned because an internal error has occurred. Try again later. If the problem persists, submit a ticket.
400 ReleaseTimeHaveBeenSet The specified instance has been set released time. The error message returned because the automatic release time has been set for the specified instance.
403 InvalidAccountStatus.NotEnoughBalance Your account does not have enough balance. The error message returned because your account balance is insufficient. You must top up your account before proceeding.
403 Account.Arrearage Your account has an outstanding payment. The error message returned because your account has overdue payments.
400 Throttling Request was denied due to request throttling, please try again after 5 minutes. The error message returned because your current request is denied due to throttling. Try again five minutes later.
403 InvalidParameter.NotMatch %s The error message returned because the specified parameter is invalid. Check whether the parameter conflicts with another parameter.
403 InvalidAction %s The error message returned because this operation is invalid.
400 Throttling %s The error message returned because the request is denied due to throttling.
400 QuotaExceed.AfterpayInstance The maximum number of Pay-As-You-Go instances is exceeded: %s The error message returned because the pay-as-you-go resources of the specified instance type are insufficient. Reduce the number of instances to be created.
400 InvalidParameter.Bandwidth %s The error message returned because the specified bandwidth is invalid. Check whether the parameter is correct.
400 InvalidPeriod.UnitMismatch The specified Period must be correlated with the PeriodUnit. The error message returned because the specified renewal period is not associated with PeriodUnit.
400 InvalidImageType.NotSupported %s The error message returned because the specified image type is invalid. Check whether the region supports this image type.
400 InvalidPeriod.ExceededDedicatedHost Instance expired date can't exceed dedicated host expired date. The error message returned because the expiration date of the instance is later than that of the dedicated host.
400 InvalidMarketImageChargeType.NotSupport The specified chargeType of marketImage is unsupported. The error message returned because the charge type of the Alibaba Cloud Marketplace image is not supported.
403 QuotaExceed.PostPaidDisk Living postPaid disks quota exceeded. The error message returned because the maximum number of pay-as-you-go disks has been reached.
403 ImageNotSupportInstanceType The specified instanceType is not supported by instance with marketplace image. The error message returned because the specified Alibaba Cloud Marketplace image does not support the instance type.
403 InvalidInstanceType.PhasedOut This instanceType is no longer offered. The error message returned because the specified instance type is no longer available.
400 InvalidSystemDiskCategory.ValueNotSupported %s The error message returned because the operation is not applicable to the specified system disk category.
500 InternalError The request processing has failed due to some unknown error. The error message returned because an internal error has occurred. Try again later. If the problem persists, submit a ticket.
403 RealNameAuthenticationError Your account has not passed the real-name authentication yet. The error message returned because you have not completed the real-name authentication. Complete the real-name authentication and try again.

For a list of error codes, visit the API Error Center.