> 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/associatesubnetinstances.md).

# AssociateSubnetInstances

## 1. API Description

This API (AssociateSubnetInstances) is used to add one or more instances into a subnet and assign private IPs to instances.

{% 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 of</mark> <mark style="color:blue;">`privateIpStatus`</mark><mark style="color:blue;">.</mark>
  * <mark style="color:blue;">If the status is</mark> <mark style="color:blue;">`BINDED`</mark><mark style="color:blue;">, it means that the private IP has been bound.</mark>
  * <mark style="color:blue;">If the status is</mark> <mark style="color:blue;">`BINDING`</mark><mark style="color:blue;">, it means that the private IP is being bound.</mark>
  * <mark style="color:blue;">If the status is</mark> <mark style="color:blue;">`UNBINDING`</mark><mark style="color:blue;">, it means that the private IP is being unbound.</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;">Instances can only be added into the subnet in the same zone.</mark>
* <mark style="color:blue;">The status of subnet should be AVAILABLE and there are still available private IPs in it.</mark>
* <mark style="color:blue;">Generally, an instance can only be added into one subnet. If the instance is already in other subnet, the request will fail. However, if you do need to add one instance into two or more subnets, please contact Zenlayer Support.</mark>
* <mark style="color:blue;">Batch operations are supported. Each request can add up to 100 instances.</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.         |
| subnetInstanceList | Yes      | Array of [AssociateSubnetInstance](/api-reference/compute/bmc/datastructure.md#associatesubnetinstance) | List of instances. |

## 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 instance into a subnet and assign a private IP to it.

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

Request:
{
  "subnetId": "833049815985166808",
  "subnetInstanceList": [
    {
      "instanceId": "820653960707704280",
      "privateIpAddress": "10.0.0.2"
    }
  ]
}

Response:
{
  "requestId": "TD3AA7771-C9C1-4EC2-A743-FD934710CEB6",
  "response": {
    "requestId": "TD3AA7771-C9C1-4EC2-A743-FD934710CEB6"
  }
}
```

{% 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\_PARAMETER\_LAN\_IP\_NOT\_SUPPORT         | Private IP ended with .1 cannot be assigned.                           |
| 403              | OPERATION\_DENIED\_IP\_ASSOCIATED\_INSTANCE       | Unavailable private IP. This has already been assigned to an instance. |
| 404              | INVALID\_SUBNET\_NOT\_FOUND                       | Subnet not found.                                                      |
| 403              | OPERATION\_DENIED\_DIFFERENT\_ZONE                | Instances can only be added into the subnet in the same zone.          |
| 400              | INVALID\_PARAMETER\_DUPLICATE\_LAN\_IP            | Duplicated private IPs assigned to instances.                          |
| 403              | OPERATION\_DENIED\_SUBNET\_STATUS\_NOT\_SUPPORT   | Subnet status not supported.                                           |
| 403              | OPERATION\_DENIED\_SUBNET\_EXIST\_INSTANCE        | Instance already exists in the subnet.                                 |
| 403              | OPERATION\_DENIED\_INSTANCE\_NOT\_SUPPORT\_SUBNET | Operations on adding the instance into a subnet not supported.         |
| 403              | OPERATION\_DENIED\_INSTANCE\_NOT\_RUNNING         | Only operations on instances in RUNNING status are supported.          |
| 403              | OPERATION\_DENIED\_SUBNET\_NOT\_REPEAT\_INSTANCE  | Duplicated instances in the subnet.                                    |


---

# 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/associatesubnetinstances.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.
