> 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/compute/bmc/vpc/subnet/associatevpcsubnet.md).

# AssociateVpcSubnet

## 1. API Description

This API (AssociateVpcSubnet) is used to add a subnet into a VPC.

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

* <mark style="color:blue;">This API is an async API. A request ID is returned after the request is sent. However, it does not mean the binding has been completed. You can use</mark> [<mark style="color:purple;">`DescribeSubnets`</mark>](/api-reference/compute/bmc/vpc/subnet/describesubnets.md) <mark style="color:blue;">to query the status.</mark>
* <mark style="color:blue;">Only operations on instances in</mark> <mark style="color:blue;">`RUNNING`</mark> <mark style="color:blue;">status are supported.</mark>
* <mark style="color:blue;">CIDR block of the subnet should be in the range of VPC CIDR block and not overlap with IP ranges of other subnets in this VPC.</mark>
* <mark style="color:blue;">Zone of the subnet should be in the availability region of the VPC. You can call</mark> [<mark style="color:purple;">`DescribeVpcAvailableRegions`</mark>](https://github.com/zenlayer/zenlayercloud-api-doc-en/blob/main/bmc/vpc/subnet/describevpcavailableregions.md) <mark style="color:blue;">to check the zones in</mark> <mark style="color:blue;">the availability region.</mark>
* <mark style="color:blue;">No action will be made against</mark> <mark style="color:blue;">the subnet already in the VPC.</mark>
* <mark style="color:blue;">Both the status of VPC and subnet should be AVAILABLE.</mark>
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name | Required | Type   | Description |
| -------------- | -------- | ------ | ----------- |
| subnetId       | Yes      | String | Subnet ID.  |
| vpcId          | Yes      | String | VPC ID.     |

## 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> |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
Add a subnet into a VPC.

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

Request:
{
  "subnetId": "426257512392561112",
  "vpcId": "835957634816289496"
}

Response:
{
  "requestId": "T7D2DD189-870C-4B13-B812-0A3C7B8D83F1",
  "response": {
    "requestId": "T7D2DD189-870C-4B13-B812-0A3C7B8D83F1"
  }
}
```

{% 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                                                       |
| ---------------- | --------------------------------------------------- | ----------------------------------------------------------------- |
| 403              | OPERATION\_DENIED\_VPC\_ZONE\_SUBNET\_EXCEED\_LIMIT | Quantity of subnets exceeds the limit of the zone.                |
| 404              | INVALID\_SUBNET\_NOT\_FOUND                         | Subnet not found.                                                 |
| 403              | OPERATION\_DENIED\_SUBNET\_ASSOCIATED\_OTHER\_VPC   | Subnet is in other VPC.                                           |
| 403              | OPERATION\_DENIED\_NO\_AVAILABLE\_VPC\_REGION       | Invalid availability region ID of VPC.                            |
| 403              | OPERATION\_DENIED\_SUBNET\_STATUS\_NOT\_SUPPORT     | Subnet status not supported.                                      |
| 403              | OPERATION\_DENIED\_ZONE\_NOT\_BELONG\_VPC           | Zone of subnet does not belong to the availability region of VPC. |
| 404              | INVALID\_VPC\_NOT\_FOUND                            | VPC not found.                                                    |
| 403              | OPERATION\_DENIED\_VPC\_STATUS\_NOT\_SUPPORT        | VPC status not supported.                                         |
| 400              | INVALID\_PARAMETER\_VPC\_SUBNET\_OVER\_LAP          | Overlapped CIDR blocks of subnets in VPC.                         |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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/vpc/subnet/associatevpcsubnet.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.
