> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/api-reference/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/api-reference/zec/vpc-network/createsubnets.md).

# CreateSubnets

## 1. API Description

This API (CreateSubnets) is used to creates multiple subnets in batches under the same VPC.

{% hint style="info" %}
**Notes**

* The subnets created in a batch must belong to the same VPC, and up to 10 subnets can be created in a single request.
* The subnets in the batch are either all created successfully or none of them is created: as long as the parameter validation or creation of any subnet fails, the entire request does not create any subnet.
* The number of subnet resources that can be created in the same VPC is also limited, and the CIDR block of each subnet must fall within the CIDR block of the VPC.
* Within the same VPC, the CIDR blocks of subnets cannot overlap, and the CIDR blocks of the subnets in this request cannot overlap with each other either: a conflict with an existing subnet under the VPC returns `OPERATION_DENIED_SUBNET_CIDR_CONFLICT`, and a conflict with another subnet in this request returns `OPERATION_DENIED_SUBNET_CIDR_CONFLICT_WITH_BATCH`.
* Call the [DescribeSubnetRegions](/api-reference/zec/vpc-network/describesubnetregions.md) interface to query whether subnet creation is supported in a region.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name | Required | Type                                                                              | Description                                                                                                                                                                                                                              |
| -------------- | -------- | --------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| vpcId          | Yes      | String                                                                            | <p>ID of the VPC to which the subnets are to be added.</p><p>All subnets created in the batch belong to the same VPC.</p><p>It can be obtained by calling <a href="/api-reference/zec/vpc-network/describevpcs.md">DescribeVpcs</a>.</p> |
| subnets        | Yes      | Array of [SubnetCreateItem](/api-reference/zec/datastructure.md#subnetcreateitem) | <p>The list of subnets to be created.</p><p>A single request supports creating up to 10 subnets.</p><p>Subnets within this batch are created all-or-nothing.</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> |
| subnetIds      | Array of String | The list of created subnet IDs, in the same order as the subnet list in the request.                                  |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**1. Batch create 2 subnets under the same VPC.**

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

Request：
{
  "vpcId": "<vpcId>",
  "subnets": [
    {
      "regionId": "asia-east-1",
      "stackType": "IPv4_IPv6",
      "ipv6Type": "Public",
      "name": "Subnet-asia-east-1-01",
      "cidrBlock": "10.0.0.0/24"
    },
    {
      "regionId": "asia-east-1",
      "stackType": "IPv4",
      "name": "Subnet-asia-east-1-02",
      "cidrBlock": "10.0.1.0/24"
    }
  ]
}

Response：
{
  "requestId": "TBFC01FCF-6439-4530-ADBC-16809F0C3E8F",
  "response": {
    "requestId": "TBFC01FCF-6439-4530-ADBC-16809F0C3E8F",
    "subnetIds": ["xxxx1", "xxxx2"]
  }
}
```

{% 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                                                                                  |
| ---------------- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------- |
| 400              | INVALID\_CIDR\_BLOCK\_FORMAT                           | Invalid CIDR block format.                                                                   |
| 400              | INVALID\_CIDR\_BLOCK\_NOT\_EMPTY                       | CIDR block cannot be empty.                                                                  |
| 400              | INVALID\_CIDR\_BLOCK\_STATUS                           | The CIDR block state is invalid.                                                             |
| 404              | INVALID\_CIDR\_IPV6\_NOT\_FOUND                        | The IPv6 CIDR block does not exist.                                                          |
| 400              | INVALID\_CIDR\_IPV6\_ONLY                              | IPv6 stack type is specified only.                                                           |
| 400              | INVALID\_CIDR\_REGION\_MISMATCH                        | The subnet region does not match the IPv6 CIDR block region.                                 |
| 404              | INVALID\_DHCP\_OPTIONS\_SET\_NOT\_FOUND                | The DHCP options set is not found.                                                           |
| 400              | INVALID\_IP\_BROADCAST\_ADDRESS                        | The IP address cannot be a broadcast address.                                                |
| 400              | INVALID\_MASK\_LENGTH                                  | The IPv6 address mask length must be greater than or equal to the subnet IPv6 prefix length. |
| 400              | INVALID\_PARAMETER\_SUBNET\_CIDR\_NOT\_BELONG\_VPC     | The subnet does not belong to the specified VPC.                                             |
| 400              | INVALID\_PARAMETER\_SUBNET\_IPV6\_TYPE\_NOT\_FOUND     | The parameter ipv6Type is missing.                                                           |
| 404              | INVALID\_REGION\_NOT\_FOUND                            | The specified region does not exist.                                                         |
| 400              | INVALID\_REGION\_NOT\_ON\_SALE                         | Subnet is not available for sale in the specified region.                                    |
| 400              | INVALID\_SUBNET\_NETMASK\_MAX\_RANGE                   | Subnet mask length exceeds the maximum value.                                                |
| 404              | INVALID\_VPC\_NOT\_FOUND                               | The global VPC does not exist.                                                               |
| 400              | OPERATION\_DENIED\_CIDR\_BLOCK\_IS\_EXIST              | CIDR block already exists.                                                                   |
| 400              | OPERATION\_DENIED\_NO\_AVAILABLE\_CIDR                 | No available CIDR block.                                                                     |
| 400              | OPERATION\_DENIED\_REGION\_NOT\_SUPPORT\_PUB\_IPV6     | Public IPv6 is not supported in the specified region.                                        |
| 400              | OPERATION\_DENIED\_SUBNET\_CIDR\_CONFLICT              | Subnet CIDR ranges conflict.                                                                 |
| 400              | OPERATION\_DENIED\_SUBNET\_CIDR\_CONFLICT\_WITH\_BATCH | The subnet CIDR conflicts with another subnet in this batch creation request.                |
| 400              | OPERATION\_DENIED\_VPC\_NOT\_SUPPORT\_PRI\_IPV6        | Private IPv6 is not supported for the specified global VPC.                                  |
