# CreateInstances

## 1. API Description

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

#### Prerequisites

* Query stock: call [`DescribeAvailableResources`](/api-reference/compute/bmc/bare-metal-instance/describeavailableresources.md) to check available resources.
* Query key pairs: call [`DescribeKeyPairs`](https://github.com/zenlayer/zenlayercloud-api-doc-en/blob/main/security/key-service/key-pair/describekeypairs.md) to check information on key pair ID.
* Query instance model: call [`DescribeInstanceTypes`](/api-reference/compute/bmc/bare-metal-instance/describeinstancetypes.md) to check specifications.
* Query image: call [`DescribeImages`](/api-reference/compute/bmc/bare-metal-instance/describeimages.md) to check information on image.
* Cost estimation: know of bare metal cloud pricing. See [Billing Method](https://docs.console.zenlayer.com/welcome/pricing/bare-metal-cloud-pricing/billing-method) for more details.

{% 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;">`CREATING`</mark> <mark style="color:blue;">during the creation. You can use</mark> [<mark style="color:purple;">DescribeInstances</mark>](/api-reference/compute/bmc/bare-metal-instance/describeinstances.md) <mark style="color:blue;">to query the status of the instance. If the status changes from</mark> <mark style="color:blue;">`PENDING`</mark> <mark style="color:blue;">or</mark> <mark style="color:blue;">`Creating`</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;">`CREATE_FAILED`</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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| instanceChargeType      | Yes      | [ChargeType](/api-reference/compute/bmc/datastructure.md#chargetype)                 | <p>Instance pricing model .</p><p>PREPAID :subscription</p><p>POSTPAID :pay-as-you-go</p><p>Only PREPAID is supported currently.If you need POSTPAID ,contact us.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| instanceTypeId          | Yes      | String                                                                               | <p>Instance model ID.</p><p>To view specific values,you can call DescribeInstanceTypes .</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| internetChargeType      | Yes      | [InternetChargeType](/api-reference/compute/bmc/datastructure.md#internetchargetype) | Network pricing model.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| instanceChargePrepaid   | No       | [ChargePrepaid](/api-reference/compute/bmc/datastructure.md#chargeprepaid)           | Details of the monthly subscription,including the purchase period,auto-renewal.It is required if the instanceChargeType is PREPAID .                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| imageId                 | No       | String                                                                               | <p>Valid image ID.</p><p>To obtain valid image ID,you can call DescribeImages ,pass in instanceTypeId to retrieve the list of images supported by the current model,and then find the imageId in the response.</p><p>You can also not specify an image and install it later through IPMI.</p><p>When using iPXE to install OS,pass the value of ipxeUrl ,and leave imageId empty.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| resourceGroupId         | No       | String                                                                               | Resource group ID where the instances reside                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| 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:</p><p>Spaces are not supported in the pattern string. Multiple pattern strings are supported,such as server\_\[3,3]\_\[1,1] .</p> |
| hostname                | No       | String                                                                               | <p>Instance hostname.</p><p>Default value:hostname.</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:</p><p>Spaces are not supported in the pattern string. Multiple pattern strings are supported,such as server\_\[3,3]\_\[1,1] .</p>           |
| amount                  | No       | Integer                                                                              | <p>The number of instances to be purchased.</p><p>Value range:\[1,100].Default value:1.</p><p>Value range: \[1, 100]</p><p>Default value: 1</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| password                | No       | String                                                                               | <p>Instance password.</p><p>The parameter must be 8-16 characters,including uppercase letters,lowercase letters,numbers and special characters like 1\~!@$^\*-\_=+ .This password is also used as the password for IPMI login.Please keep it safe.</p><p>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.Call DescribeKeyPairs to obtain key pair information.</p><p>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>                                                                                                                                                                                                                                                                                                                                                                                                 |
| 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.</p><p>Value range: \[1, +)</p><p>Default value: 1</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| 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>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| subnetId                | No       | String                                                                               | <p>Subnet ID.</p><p>Call DescribeVpcSubnets to check information on subnets created.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| raidConfig              | No       | [RaidConfig](/api-reference/compute/bmc/datastructure.md#raidconfig)                 | Disk array configuration.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| partitions              | No       | Array of [Partition](/api-reference/compute/bmc/datastructure.md#partition)          | <p>Disk partition configuration.</p><p>If the operating system is not installed,the partition cannot be set.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| nic                     | No       | [Nic](/api-reference/compute/bmc/datastructure.md#nic)                               | NIC configuration.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ipxeUrl                 | No       | String                                                                               | <p>iPXE URL.</p><p>Pass in the value and install your OS via IPMI.</p><p>You can choose to install OS using Netboot.See Deploy a Custom Image Using iPXE for more details.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| userData                | No       | String                                                                               | <p>User Data.</p><p>You can specify user data during instance installation. When the instance is launched for the first time, the user data is passed to the server as text and executed. The maximum supported data size is 32 KB.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| enablePrimaryIPv6       | No       | Boolean                                                                              | <p>Enable primary IPv6 or not.</p><p>If the value is false ,the primary IPv6 is not enabled and the elastic IPv6 cannot be configured.</p><p>The default value is true .</p><p>Default value: true</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| clusterId               | No       | String                                                                               | Bandwidth cluster ID.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| marketingOptions        | No       | [MarketingInfo](/api-reference/compute/bmc/datastructure.md#marketinginfo)           | Information on marketing campaigns.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| tags                    | No       | [TagAssociation](/api-reference/compute/bmc/datastructure.md#tagassociation)         | <p>Bound tags when creating resources.</p><p>Tag keys must be unique.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| enableGatewayMode       | No       | Boolean                                                                              | <p>Whether to enable Gateway Mode.</p><p>Enables the host-bound IPs to act as a gateway for downstream traffic. Only elastic IPs are supported. Additional configuration on the host is required; when disabled, standard routing mode applies.</p><p>Note: Gateway mode is not supported by default. Please contact Console Support if you need to enable this feature.</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>                                                                                                                                                                                                                                                                                                              |
| 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 CREATING during the creation.uery the status of the instance according to dataSet . If the status changes from PENDING or Creating to Running , it means that the instance has been created successfully; CREATE\_FAILED means the instance has been created failed.</p> |
| orderNumber    | String          | Number of order.                                                                                                                                                                                                                                                                                                                                                                                                                   |

## 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 M6C, 1 Mbps flat rate bandwidth billing method, random system-generated password, and no images installed.

<pre class="language-json"><code class="lang-json">POST /api/v2/bmc HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreateInstances


Request:
<strong>{
</strong>    "instanceChargeType": "POSTPAID",
    "instanceTypeId": "M6C",
    "internetChargeType": "ByBandwidth",
    "zoneId": "SEL-A"
}

Response:
{
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "response": {
        "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
        "instanceIdSet": ["instanceId1"],
        "orderNumber" : "orderNumber1"
    }
}
</code></pre>

{% endtab %}
{% endtabs %}

## 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                                                                                                       |
| --------------------------------------------------------------------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| 404                                                                   | INVALID\_ZONE\_NOT\_FOUND                                  | Zone not found.                                                                                                   |
| 400                                                                   | INVALID\_PARAMETER\_VALUE\_RAID\_DISK\_SEQUENCE\_RANGE     | The disk sequence number in custom RAID configuration exceeds the number of disks supported by the instance type. |
| 404                                                                   | INVALID\_SUBNET\_NOT\_FOUND                                | Subnet not found.                                                                                                 |
| 404                                                                   | INVALID\_INSTANCE\_TYPE\_NOT\_FOUND                        | Instance type not found.                                                                                          |
| 400                                                                   | INVALID\_PARAMETER\_VALUE\_RAID\_DISK\_SEQUENCE\_DUPLICATE | Duplicated disk sequence number in the custom RAID configuration.                                                 |
| 400                                                                   | INVALID\_PARAMETER\_INSTANCE\_LOGIN\_CONFLICT              | Password login and SSH key login cannot be specified at the same time.                                            |
| 400                                                                   | INVALID\_PARTITION\_MALFORMED                              | Invalid file type or path format.                                                                                 |
| 404                                                                   | INVALID\_IMAGE\_NOT\_FOUND                                 | Image not found.                                                                                                  |
| 400                                                                   | INVALID\_PARAMETER\_NIC\_NAME\_MALFORMED                   | Invalid public or private NIC name.                                                                               |
| 400                                                                   | INVALID\_INSTANCE\_TYPE\_RAID\_NOT\_SUPPORT                | RAID level not supported for current instance model.                                                              |
| 400                                                                   | INVALID\_RAID\_CONFIG\_FAST\_CUSTOM\_CONFLICT              | Custom RAID and rapid RAID cannot be specified at the same time.                                                  |
| 403                                                                   | INVALID\_CHARGE\_TYPE\_NOT\_SUPPORT                        | The current account does not support the specified pricing model.                                                 |
| 403                                                                   | OPERATION\_DENIED\_INSTANCE\_QUOTA\_EXCEED                 | The number of machine creations has exceeded the total quota for the current Team.                                |
| 400                                                                   | INVALID\_PARAMETER\_SSH\_KEY\_DUPLICATE                    | Invalid SSH key pair; duplicate values exist.                                                                     |
| 400                                                                   | INVALID\_INSTANCE\_TYPE\_QUICK\_RAID\_NOT\_SUPPORT         | Rapid RAID not supported. Please customize RAID settings.                                                         |
| 400                                                                   | INVALID\_PARAMETER\_NIC\_NAME\_CONFLICT                    | Public NIC name and private NIC name cannot be the same.                                                          |
| 400                                                                   | INVALID\_PARAMETER\_VALUE\_PASSWORD\_MALFORMED             | Invalid password.                                                                                                 |
| 400                                                                   | INVALID\_PARTITION\_NO\_TYPE                               | Invalid file type.                                                                                                |
| 400                                                                   | INVALID\_PARTITION\_INVALID\_ORDER                         | Drive letters must be filled in alphabetical order, such as CDEFG for Windows.                                    |
| 400                                                                   | INVALID\_SUBNET\_PRIVATE\_IP\_INSUFFICIENT                 | Insufficient private IP addresses in the subnet to assign to the created instances.                               |
| 400                                                                   | INVALID\_PARTITION\_MISSING\_REQUIRED\_FILE\_PATH          | File path (drive letter) is needed.                                                                               |
| "c" must be included for Windows, and "/" must be included for Linux. |                                                            |                                                                                                                   |
| 400                                                                   | INVALID\_PARAMETER\_SSH\_KEY\_MALFORMED                    | Invalid SSH key format. Usually start with rsa .                                                                  |
| 400                                                                   | INVALID\_PARTITION\_DUPLICATE\_FILE\_PATH                  | Duplicated file path or drive letters of the partition.                                                           |
| 400                                                                   | INVALID\_PARAMETER\_VALUE\_RAID\_DISK\_MISMATCH            | Disk quantity does not meet the RAID level requirement in custom RAID configuration.                              |
| 400                                                                   | INVALID\_PARAMETER\_INSTANCE\_NAME\_EXCEED                 | Invalid instance name format.                                                                                     |
| 403                                                                   | INVALID\_PARTITION\_IMAGE\_NOT\_SET                        | Custom partition are only supported for specific operating system.                                                |
| 400                                                                   | INVALID\_PARAMETER\_HOSTNAME\_EXCEED                       | Invalid hostname length. The specified hostname exceeds the maximum length.                                       |
| 400                                                                   | INVALID\_SUBNET\_ZONE\_MISMATCH                            | The subnet is not in the specified availability zone.                                                             |
| 400                                                                   | INVALID\_PARAMETER\_VALUE\_RAID\_DISK\_DISORDER            | Serial numbers of disks must be filled in order, such as \[1,2,3], in custom RAID configuration.                  |
| 400                                                                   | INVALID\_PARAMETER\_HOSTNAME\_MALFORMED                    | Invalid hostname format.                                                                                          |


---

# 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/bmc/bare-metal-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.
