# CreateInstances

## 1. API Description

This API (CreateInstances) is used to create one or more virtual machine instances with a specified configuration.

#### Prerequisites

* Query instance model: call [`DescribeZoneInstanceConfigInfos`](/api-reference/compute/vm/virtual-machine-instance/describezoneinstanceconfiginfos.md) to check specifications.
* Query image: call [`DescribeImages`](/api-reference/compute/vm/image/describeimages.md) to check information on image.

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>

* <mark style="color:blue;">After an instance is created successfully, it will start up automatically, and the instance status will become "</mark><mark style="color:blue;">`RUNNING`</mark><mark style="color:blue;">".</mark>
* <mark style="color:blue;">If you create a subscription instance, the amount required will be pre-deducted. If the balance is insufficient, the request will fail. If you create a pay-as-you-go instance, please ensure your account balance is sufficient before calling this API.</mark>
* <mark style="color:blue;">Vouchers can be used for fee deduction in instance creation. See</mark> [<mark style="color:purple;">Vouchers</mark>](https://docs.console.zenlayer.com/welcome/platform/billing-center/vouchers) <mark style="color:blue;">for more details.</mark>
* <mark style="color:blue;">This API is an async API. An instance ID list is returned after the creation request is sent. However, it does not mean the creation has been completed. The status of the instance will be</mark> <mark style="color:blue;">`PENDING`</mark> <mark style="color:blue;">or</mark> <mark style="color:blue;">`DEPLOYING`</mark> <mark style="color:blue;">during the creation. You can use</mark> <mark style="color:purple;">`DescribeInstances`</mark> <mark style="color:blue;">to query the status of the instance. If the status</mark> <mark style="color:blue;">(</mark><mark style="color:blue;">`instanceStatus`</mark><mark style="color:blue;">)</mark> <mark style="color:blue;">changes from</mark> <mark style="color:blue;">`PENDING`</mark> <mark style="color:blue;">or</mark> <mark style="color:blue;">`DEPLOYING`</mark> <mark style="color:blue;">to</mark> <mark style="color:blue;">`Running`</mark><mark style="color:blue;">, it means that the instance has been created successfully;</mark> <mark style="color:blue;">if no instance has been queried, it</mark> <mark style="color:blue;">means the instance has been created failed. Any operations on the instances are not allowed while creating.</mark>
* <mark style="color:blue;">A maximum of 100 instances can be created in one request.</mark>
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name          | Required | Type                                                                                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ----------------------- | -------- | ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| zoneId                  | Yes      | String                                                                              | Zone ID to which the instances belong.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| imageId                 | Yes      | String                                                                              | <p>Valid image ID.</p><p>To obtain valid image ID, you can call DescribeImages, and find imageId in the response.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| instanceType            | Yes      | String                                                                              | <p>Instance model ID.</p><p>To view specific values, you can call</p><p>DescribeZoneInstanceConfigInfos.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| instanceChargeType      | Yes      | [ChargeType](/api-reference/compute/vm/datastructure.md#chargetype)                 | <p>Instance pricing model.</p><p>PREPAID: subscription</p><p>POSTPAID: pay-as-you-go.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| internetChargeType      | Yes      | [InternetChargeType](/api-reference/compute/vm/datastructure.md#internetchargetype) | <p>Public network pricing model.</p><p>See InternetChargeType for details.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| instanceCount           | Yes      | Integer                                                                             | <p>The number of instances to be purchased.</p><p>Value range: \[1,100].</p><p>Default value: 1.</p><p>Value range: \[1, 100]</p><p>Default value: 1</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| subnetId                | Yes      | String                                                                              | Subnet ID.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| instanceName            | No       | String                                                                              | <p>Instance name to be displayed.</p><p>Default value: instance.</p><p>This parameter can contain up to 64 characters. Only letters, numbers, - and periods (.) are supported.</p><p>If you purchase multiple instances at the same time, you can specify a pattern string \[begin\_number,bits].</p><p>begin\_number: the starting value of an ordered number, value range: \[0,99999], default value: 0.</p><p>bits: the number of digits occupied by an ordered value, value range: \[1,6], default value: 6.</p><p>For example, if you purchase 1 instance and the instance name body is server\_\[3,3], the instance name will be server003; if you purchase 2 instances, the instance names will be server003, server004.</p><p>Note:Spaces are not supported in the pattern string.Multiple pattern strings are supported, such as server\_\[3,3]\_\[1,1].</p> |
| password                | No       | String                                                                              | <p>Instance password.</p><p>The parameter must be 8-16 characters, including:lowercase letters: \[a-z]uppercase letters: \[A-Z]digits: 0-9special characters: !@#$%^&\*\`\~()-+=You must and can only pass the value of either password or keyId.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| keyId                   | No       | String                                                                              | <p>SSH key pair ID.</p><p>Your SSH key pair contains several public keys that can be placed on your server. You can access your instance with the private key. SSH key pairs and passwords cannot to set at the same time. SSH key pairs are not supported for Windows operating system.</p><p>For example: key-YWD2QFOl</p><p>You must and can only pass the value of either password or keyId.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| resourceGroupId         | No       | String                                                                              | <p>Resource group ID where the instances reside.</p><p>If the value is empty, the instance will be added into the default resource group.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| instanceChargePrepaid   | No       | [ChargePrepaid](/api-reference/compute/vm/datastructure.md#chargeprepaid)           | Details of the monthly subscription, including the purchase period, auto-renewal. It is required if the instanceChargeType is PREPAID.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| instanceChargePostpaid  | No       | [ChargePostpaid](/api-reference/compute/vm/datastructure.md#chargepostpaid)         | Postpaid mode parameter settings.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| trafficPackageSize      | No       | Float                                                                               | <p>Traffic package size (TB).</p><p>The parameter is valid only when internetChargeType is ByTrafficPackage.</p><p>If not passed in, the default value will be the size of the free traffic package.</p><p>Value range: \[0.0, +)</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| internetMaxBandwidthOut | No       | Integer                                                                             | <p>Public network bandwidth cap (Mbps).</p><p>Default value: 1 Mbps.</p><p>The parameter value differs with different instance models. See bandwidth configuration for details.</p><p>Value range: \[1, +)</p><p>Default value: 1</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| systemDisk              | No       | [SystemDisk](/api-reference/compute/vm/datastructure.md#systemdisk)                 | <p>System disk configuration.</p><p>If the value is empty, the system disk size is the minimum default value to store the operating system.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| dataDisks               | No       | Array of [DataDisk](/api-reference/compute/vm/datastructure.md#datadisk)            | <p>Data disk configuration.</p><p>If the value is empty, no data disk is attached by default.</p><p>Only 10 data disk can be attached along with the instance for now.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| enableIpv6              | No       | Boolean                                                                             | Whether enable public IPv6 or not.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| enableIpv4              | No       | Boolean                                                                             | Whether to enable public IPv4.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| cpuPassThrough          | No       | Boolean                                                                             | Whether CPU passthrough is enabled.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| initScript              | No       | String                                                                              | Initialize the script. The string's byte size must not exceed 32 KB.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| networkMode             | No       | [NetworkMode](/api-reference/compute/vm/datastructure.md#networkmode)               | Network interface mode.Vf: VFIO ModeVirtio: Virtio-net Mode                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| diskPreAllocated        | No       | Boolean                                                                             | Pre allocate disk performance                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| nic                     | No       | [Nic](/api-reference/compute/vm/datastructure.md#nic)                               | Name of network interface configuration.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| securityGroupId         | No       | String                                                                              | <p>Security group ID.</p><p>To obtain security group ID, you can call DescribeSecurityGroups , and find sgId in the response.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| clusterId               | No       | String                                                                              | Bandwidth cluster ID.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| cidrBlockId             | No       | String                                                                              | CIDR Address Block ID. This field specifies the public IP address to be assigned from the CIDR address block.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| startCidrIpv4           | No       | String                                                                              | <p>The starting IP address within the CIDR address range.</p><p>This field requires the quota <code>cidrBlockId</code> to be used together, and it represents the public IP address to be assigned to the machine from the address range starting at this address.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| marketingOptions        | No       | [MarketingInfo](/api-reference/compute/vm/datastructure.md#marketinginfo)           | Information on marketing campaigns.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| tags                    | No       | [TagAssociation](/api-reference/compute/vm/datastructure.md#tagassociation)         | <p>Tags associated when creating resources.</p><p>Note: The associated tag key cannot be duplicated.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

## 3. Output Parameters

| Parameter Name | Type                                                                                     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| -------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| requestId      | String                                                                                   | <p>The unique request ID, which is returned for each request.</p><p>RequestId is required for locating a problem.</p>                                                                                                                                                                                                                                                                                                                                                                       |
| orderNumber    | String                                                                                   | Number of order.                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| instanceIdSet  | Array of String                                                                          | <p>List of instance IDs.</p><p>The returned instance ID list does not mean the creation has been completed. The status of the instance will be PENDING or DEPLOYING during the creation. You can call DescribeInstances to query the status of the instance according to dataSet. If the status changes from PENDING or DEPLOYING to RUNNING, it means that the instance has been created successfully; CREATE\_FAILED or no instance found means the instance has been created failed.</p> |
| instances      | Array of [DiskWithInstance](/api-reference/compute/vm/datastructure.md#diskwithinstance) | Set of data disk IDs created along with the instances. If no data disk is specified, the value is empty.                                                                                                                                                                                                                                                                                                                                                                                    |

## 4. Code Example

{% tabs %} {% tab title="Example" %}

**Create a pay-as-you-go instance with the simplest parameters**

Assuming to create a pay-as-you-go instance in `Seoul A` with the model of `1c2g`, `1 Mbps` flat rate bandwidth billing method, random system-generated password, and no images installed.

```json
POST /api/v2/vm HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreateInstances
<Common Request Params>

Request:
{
    "zoneId":"SEL-A",
    "instanceType":"c.1c2g",
    "imageId":"img-yKK4q6XybymPgfx7ynUUqC3N8",
    "instanceChargeType":"POSTPAID",
    "internetChargeType":"ByBandwidth"
}

Response:
{
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "response": {
        "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
        "instanceIdSet": ["instanceId1"],
        "orderNumber" : "the id of order number",
        "instances":[{"instanceId":"instanceId1","diskIdSet":[]}]
    }
}
```

## 5. Developer Resources

Zenlayer Cloud API 2.0 integrates [SDKs](/api-reference/api-introduction/toolkit/api-sdk.md)，to make it easier for you to call APIs. More programming languages will be supported.

## 6. Error Codes

The following only lists the error codes related to the API business logic. For other error codes, see [Common Error Codes](/api-reference/api-introduction/instruction/commonerrorcode.md).

| HTTP Status Code | Error Code                                              | Description                                                                                                                                                  |
| ---------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 400              | INVALID\_PARAMETER\_INSTANCE\_NAME\_EXCEED              | Invalid instance name length. The specified instance name exceeds the maximum length.                                                                        |
| 400              | INVALID\_PARAMETER\_INSTANCE\_NAME\_MALFORMED           | Invalid instance name format.                                                                                                                                |
| 403              | OPERATION\_FILED\_INTERNET\_CHARGE\_TYPE\_NOT\_SUPPORT  | Network billing method not supported in current zone.                                                                                                        |
| 404              | INVALID\_IMAGE\_NOT\_FOUND                              | Image not found.                                                                                                                                             |
| 404              | INVALID\_ZONE\_NOT\_FOUND                               | Zone not found.                                                                                                                                              |
| 404              | INVALID\_INSTANCE\_TYPE\_NOT\_FOUND                     | Instance model not found.                                                                                                                                    |
| 400              | INVALID\_PARTITION\_IMAGE\_NOT\_SET                     | Custom partition are only supported for specific operating system.                                                                                           |
| 403              | OPERATION\_DENIED\_INSTANCE\_QUOTA\_EXCEED              | You are trying to create more instances than your remaining quota allows.                                                                                    |
| 400              | INVALID\_BANDWIDTH\_VALUE\_EXCEED\_MAXIMUM              | Bandwidth exceeds the maximum limit.                                                                                                                         |
| 400              | INVALID\_PARAMETER\_VALUE\_PASSWORD\_MALFORMED          | Invalid password.                                                                                                                                            |
| 400              | RESOURCE\_INSUFFICIENT\_PRODUCT\_SOLD\_OUT              | Resources not for sale.                                                                                                                                      |
| 403              | OPERATION\_DENIED\_CHARGE\_TYPE\_NOT\_SUPPORT           | Pricing model not supported in current zone.                                                                                                                 |
| 400              | RESOURCES\_SOLDOUT\_INSTANCE\_TYPE                      | Instance models sold out.                                                                                                                                    |
| 400              | INVALID\_DISK\_SIZE\_LESS\_MINIMUM                      | Data disk size should be larger than the minimum limit.                                                                                                      |
| 400              | INVALID\_DISK\_SIZE\_EXCEED\_MAXIMUM                    | Data disk size exceeds the maximum limit.                                                                                                                    |
| 403              | OPERATION\_DENIED\_SUBNET\_ZONE\_MISMATCH               | Subnet the instance added in is not in the current zone.                                                                                                     |
| 400              | INVALID\_SYSTEM\_DISK\_SIZE                             | Invalid system disk size. The size should be multiples of 10 GB.                                                                                             |
| 400              | INVALID\_SYSTEM\_DISK\_EXCEED\_LIMIT                    | System disk size exceeds the maximum limit.                                                                                                                  |
| 400              | INVALID\_INSTANCE\_TYPE\_ZONE\_NO\_SELL                 | Instance model not available in the zone.                                                                                                                    |
| 400              | INVALID\_DISK\_ZONE\_NO\_SELL                           | Data disks sold out or not for sale in the current zone. You cannot create a data disk for now.                                                              |
| 403              | OPERATION\_DENIED\_INTERNET\_CHARGE\_TYPE\_NOT\_SUPPORT | Only operations on instance whose [`internetChargeType`](/api-reference/compute/vm/datastructure.md#internetchargetype) is `ByTrafficPackage` are supported. |
| 400              | INVALID\_PASSWORD\_MALFORMED                            | Invalid password format. Please check the specified restrictions again.                                                                                      |
| 400              | INVALID\_PARAMETER\_BANDWIDTH\_EXCEED                   | Bandwidth size exceeds the maximum limit.                                                                                                                    |
| 403              | OPERATION\_DENIED\_SUBNET\_IP\_INSUFFICIENT             | Insufficient private IP addresses in the subnet.                                                                                                             |
| 400              | INVALID\_PARAMETER\_TRAFFIC\_PACKAGE\_EXCEED            | Data transfer package size exceeds the upper limit.                                                                                                          |
| 400              | INVALID\_PARAMETER\_TRAFFIC\_PACKAGE                    | Invalid data transfer package size.                                                                                                                          |
| 403              | INVALID\_REGION\_SECURITY\_GROUP\_NOT\_SUPPORT          | Security groups not supported in the zone.                                                                                                                   |
| 404              | OPERATION\_DENIED\_IPV4\_CIDR\_NOT\_FOUND               | CIDR Block not found.                                                                                                                                        |
| 403              | OPERATION\_DENIED\_IPV4\_CIDR\_IP\_NOT\_ENOUGH          | CIDR Block IPv4 is not sufficient.                                                                                                                           |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/api-reference/compute/vm/virtual-machine-instance/createinstances.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
