All Products
Search
Document Center

Elastic Compute Service:ModifyInstanceChargeType

Last Updated:Sep 09, 2026

Modifies the billing method of ECS instances. Batch modification is supported.

Operation description

Before you begin

  • Make sure that you fully understand the subscription, pay-as-you-go, and other billing methods and pricing of Elastic Compute Service (ECS).

  • Make sure that the target instances are in the Running (Running) or Stopped (Stopped) state and that your account has no overdue payments.

  • After the billing method is changed, automatic payment is enabled by default. Make sure that your account balance is sufficient. Otherwise, abnormal orders are generated, and you can only cancel the orders. If your account balance is insufficient, you can set the AutoPay parameter to false. In this case, unpaid orders are generated, and you can log on to the ECS console to complete the payment.

Precautions

  • Subscription to pay-as-you-go:

  • When you convert a subscription instance to a pay-as-you-go instance, the new billing method covers the entire lifecycle of the instance. You receive a refund for the price difference, which is returned to your original payment method. Vouchers that have been redeemed are not refundable.
    • Refund rules: The refund amount that you can freely use within a month is limited and does not carry over. After the refund quota is exhausted, you can only switch between billing methods in the next month. The refund quota consumed by a single billing method switch is calculated by using the following formula: vCPUs × (refund days × 24 ± floating hours). For more information, see Change the billing method from subscription to pay-as-you-go.

  • Pay-as-you-go to subscription:
    • All pay-as-you-go data disks attached to the instance can be converted to subscription data disks at the same time.

    • If a release time has been set for the pay-as-you-go instance, you cannot call this operation. For more information, see Change the billing method from subscription to pay-as-you-go.

    • If the instance is in economical mode, start the instance first.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

ecs:ModifyInstanceChargeType

update

*Instance

acs:ecs:{#regionId}:{#accountId}:instance/{#instanceId}

None None

Request parameters

Parameter

Type

Required

Description

Example

InstanceIds

string

Yes

The IDs of instances. The value can be a JSON array that consists of up to 20 instance IDs. Separate the IDs with commas (,).

["i-bp67acfmxazb4p****","i-bp67acfmxazb4d****"]

RegionId

string

Yes

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

cn-hangzhou

Period

integer

No

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

If `PeriodUnit` is set to `Month`, valid values of `Period`: 1, 2, 3, 4, 5, 6, 7, 8, 9, and 12.

1

PeriodUnit

string

No

The unit of the renewal period, which is the unit of the Period parameter. Valid values:

Month

Default value: Month.

Month

IncludeDataDisks

boolean

No

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

  • true: Yes.

  • false: No.

Default value: false.

false

DryRun

boolean

No

Specifies whether to perform only a dry run. Valid values:

  • true: performs only a dry run. The system checks whether your AccessKey pair is valid, whether the Resource Access Management (RAM) user is granted the required authorization, and whether the required parameters are specified. If the request fails the dry run, the corresponding error is returned. If the request passes the dry run, the DryRunOperation error code is returned.

  • false: performs a dry run and sends the normal request. If the request passes the dry run, a 2xx HTTP status code is returned and the operation is performed.

Default value: false.

false

AutoPay

boolean

No

Specifies whether to enable automatic payment. Valid values:

  • true: enables automatic payment. Make sure that your account balance is sufficient. If your account balance is insufficient, abnormal orders are generated, and you can only cancel the orders.

  • false: generates orders without charging.

Default value: true.

Note

If your payment method has an insufficient balance, you can set AutoPay to false. In this case, unpaid orders are generated, and you can log on to the ECS console to complete the payment.

false

InstanceChargeType

string

No

The target billing method of the instance. Valid values:

  • PrePaid: converts pay-as-you-go instances to subscription instances.

  • PostPaid: converts subscription instances to pay-as-you-go instances.

Default value: PrePaid.

PrePaid

ClientToken

string

No

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

123e4567-e89b-12d3-a456-426655440000

IsDetailFee

boolean

No

Specifies whether to return order fee details when converting from subscription to the pay-as-you-go billing method. Valid values:

  • true: Yes.

  • false: No.

Default value: false.

false

Response elements

Element

Type

Description

Example

object

FeeOfInstances

object

FeeOfInstance

array<object>

The order fee details.

object

Currency

string

The currency unit of the bill.

China site: CNY.

International site: USD.

CNY

Fee

string

The fee amount.

0

InstanceId

string

The instance ID.

i-bp67acfmxazb4p****

OrderId

string

The order ID. This parameter is returned only when the billing method is changed to subscription.

20413515388****

RequestId

string

The request ID.

B61C08E5-403A-46A2-96C1-F7B1216DB10C

Examples

Success response

JSON format

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

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidInstance.UnpaidOrder %s
400 Throttling Request was denied due to request throttling, try again later. Requests are too frequent due to resource or account dimensions, please try again later.
400 InstanceHasProcessingConvertOrder %s
400 InvalidParameter.InstanceIds The specified InstanceIds are invalid. The specified instance is invalid.
400 InvalidParameter %s The specified parameter is invalid.
400 InvalidStatus.ValueNotSupported %s The resource is in a state that does not support the current operation.
400 InvalidInstanceChargeType.ValueNotSupported %s The specified InstanceChargeType parameter is invalid.
400 InvalidSpotStrategy The specified spotStrategy is not valid. The specified Spot Policy parameter SpotStrategy does not support this instance, or the Spot Policy attribute (Spot Instance) of this instance does not support this operation.
400 ExpiredInstance The specified instance has expired. The specified instance has expired.
400 InstancesIdQuotaExceed The maximum number of Instances is exceeded.
400 InvalidClientToken.ValueNotSupported The ClientToken provided is invalid. The specified ClientToken parameter is invalid.
400 InvalidInternetChargeType.ValueNotSupported %s The specified InternetChargeType parameter is invalid.
400 ReleaseTimeHaveBeenSet The specified instance has been set released time. An automatic release time has been set for the specified instance.
400 QuotaExceed.AfterpayInstance The maximum number of Pay-As-You-Go instances is exceeded: %s.
400 InvalidParameter.Bandwidth %s The specified bandwidth value is invalid.
400 QuotaExceed.RufundVcpu The maximum number of refund vcpu is exceeded: %s.
400 InvalidPeriod.UnitMismatch The specified Period must be correlated with the PeriodUnit. The specified Period value must fall within the valid value range that is determined based on the PeriodUnit parameter.
400 InvalidImageType.NotSupported %s The specified image type is invalid. Verify that this image type is supported in the current region.
400 InvalidPeriod.ExceededDedicatedHost Instance expired date can't exceed dedicated host expired date.
400 InvalidMarketImageChargeType.NotSupport The specified chargeType of marketImage is unsupported. The billing method of the Alibaba Cloud Marketplace image is not supported.
400 InvalidSystemDiskCategory.ValueNotSupported %s The specified system disk category is invalid.
400 InvalidAccountStatus.PayAmountLimitExceeded Your account is being restricted, due to no default payment method is set or you has not being authorized.
400 InvalidInstance.NotFoundSystemDisk The specified instance has no system disk. The specified instance does not have a system disk. Make sure that the instance has a system disk. You can call the DescribeInstances operation to query the details of the instance.
400 AccountForbidden.ProductCreationLimited The commodity must be officially operated by Aliyun and in pay-as-you-go billing method. Enterprise cloud migration customers can purchase only pay-as-you-go ECS instances and cannot purchase third-party products such as images provided by Alibaba Cloud Marketplace. Check the parameters and retry with valid parameters.
400 Invalid.PrivatePoolOptions.MatchCriteria Target mode does not support this operation. The operation is not supported while the PrivatePoolOptions.MatchCriteria parameter is set to Target.
400 InvalidPeriod The specified period is not valid. The specified period is invalid.
400 DISK_IN_DEDICATED_BLOCK_STORAGE_CLUSTER The disk in dedicated block storage cluster is not allowed to do this operation.
400 NoPermission.Price The operation requires price permission. Please either apply for permission from your main account, or set the parameter AutoPay as true. This operation requires price permission. Please apply for permission to your master account, or set the parameter AutoPay to true for automatic payment.
400 NoPermission.Refund The operation requires refund permission. Please apply for permission from your main account. This account does not have permission to operate refund, and the main account needs to authorize refund-related permissions.
400 QuotaExceeded.InternetBandwidth %s. Under your current account, the public network bandwidth of the Pay-As-You-Go ECS instance charged by fixed bandwidth exceeds the total bandwidth quota limit.
400 DiskExpiredOrInArrears Your account has an overdue payment for the specified instance. Your account has an overdue payment for the specified instance.
400 LastTokenProcessing The last token request is processing A token request is being processed. Try again later.
500 InternalError The request processing has failed due to some unknown error, exception or failure. An internal error has occurred. Try again later.
500 InvalidInstanceType.ValueUnauthorized The specified InstanceType is not authorized.
500 InvalidOperation.RefundFailed Failed to refund. Please try again or submit a support ticket. Refund failed
403 InvalidInstance.TempBandwidthUpgrade Cannot switch to Pay-As-You-Go during the period of temporary bandwidth upgrade. You cannot change the billing method of the instance to pay-as-you-go during the temporary bandwidth upgrade period.
403 InvalidInstanceType.ValueNotSupported The specified InstanceType does not exist or beyond the permitted range.
403 InstanceType.Offline %s The operation is not supported while the instance type is retired or while resources of the instance type are insufficient.
403 InvalidAccountStatus.NotEnoughBalance Your account does not have enough balance.
403 Account.Arrearage Your account has an outstanding payment.
403 InvalidParameter.NotMatch %s A specified parameter is invalid. Check whether parameter conflicts exist.
403 InvalidAction %s
403 QuotaExceed.PostPaidDisk Living postPaid disks quota exceeded. The number of pay-as-you-go disks has exceeded the allowed quota.
403 ImageNotSupportInstanceType The specified instanceType is not supported by instance with marketplace image. The specified Alibaba Cloud Marketplace image does not support the instance type.
403 InvalidInstanceType.PhasedOut This instanceType is no longer offered. The specified instance type is retired.
403 InvalidPeriod.ExceededDedicatedHost Instance expired date can't exceed dedicated host expired date.
403 RealNameAuthenticationError Your account has not passed the real-name authentication yet. You have not completed real-name verification. Complete real-name verification and try again.
403 InvalidOperation.NotSupport Instance on dedicated host not support modify charge type.
403 QuotaExceed.ElasticQuota No additional quota is available for the specified ECS instance type. The maximum number of instances of the specified instance type in the region has been reached. Reduce the quantity of instances that you want to purchase or try another region or instance type. Alternatively, you can go to the ECS console or Quota Center to request a quota increase.
403 PeriodNotSupported.InstanceOnManagedPrivateSpace The instance on ManagedPrivateSpace is not supported to modify chargeType.
403 UnsupportedIspChargeType %s The billing type does not support the service provider (ISP) for this account.
403 InvalidOperation.StoppedModeUnsupported The specified instance is StopCharging. The instance is stopped in economical mode and cannot be operated.
404 InvalidInstanceId.NotFound The specified instanceId does not exist.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.