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

# CreateHaVip

## 1. API Description

This API (CreateHaVip) is used to create a high availability virtual IP (HaVip).

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

* Each team can create up to 10 HaVips (default quota). If the quantity exceeds the limit, you can contact Support to increase the quota.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name  | Required | Type                                                                 | Description                                                                                                                                                                                                                                   |
| --------------- | -------- | -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| subnetId        | Yes      | String                                                               | <p>ID of the subnet that the HaVip belongs to.</p><p>It can be obtained by calling <a href="/api-reference/zec/vpc-network/describesubnets.md">DescribeSubnets</a>.</p>                                                                       |
| name            | Yes      | String                                                               | HaVip name. Length: 1 to 64 characters.                                                                                                                                                                                                       |
| ipAddress       | No       | String                                                               | <p>Specify the private IP address of the HaVip.</p><p>It must fall within the subnet CIDR block, and cannot be the gateway address or an address already in use.</p><p>The system allocates it automatically when it is not specified.</p>    |
| securityGroupId | No       | String                                                               | <p>Security group ID.</p><p>The default security group of the VPC is used when it is not specified.</p><p>It can be obtained by calling <a href="/api-reference/zec/security-group/describesecuritygroups.md">DescribeSecurityGroups</a>.</p> |
| tags            | No       | [TagAssociation](/api-reference/zec/datastructure.md#tagassociation) | Tags to associate with the HaVip at creation.                                                                                                                                                                                                 |

## 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> |
| haVipId        | String | The ID of the high availability virtual IP.                                                                           |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**1. Create a HaVip (auto-assign IP).**

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

Request：
{
  "subnetId": "subnet-xxxxxxxx",
  "name": "my-havip"
}

Response：
{
  "requestId": "T12345678-0000-0000-0000-000000000001",
  "response": {
    "requestId": "T12345678-0000-0000-0000-000000000001",
    "haVipId": "havip-xxxxxxxx"
  }
}
```

**2. Create a HaVip (specify IP and security group).**

```json
Request：
{
  "subnetId": "subnet-xxxxxxxx",
  "name": "my-havip-fixed",
  "ipAddress": "10.0.1.100",
  "securityGroupId": "sg-xxxxxxxx"
}

Response：
{
  "requestId": "T12345678-0000-0000-0000-000000000002",
  "response": {
    "requestId": "T12345678-0000-0000-0000-000000000002",
    "haVipId": "havip-yyyyyyyy"
  }
}
```

{% 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\_SUBNET\_NOT\_FOUND                         | Subnet does not exist.                                       |
| 400              | OPERATION\_DENIED\_SUBNET\_TYPE\_NOT\_SUPPORT\_IPV4 | Subnet type does not support IPv4.                           |
| 400              | INVALID\_SUBNET\_REGION\_NOT\_SUPPORT\_HAVIP        | The region does not support HaVip.                           |
| 409              | INVALID\_SUBNET\_IPV4\_INSUFFICIENT                 | Insufficient available IPv4 addresses in the subnet.         |
| 404              | INVALID\_SECURITY\_GROUP\_NOT\_FOUND                | The specified security group does not exist.                 |
| 409              | INVALID\_SUBNET\_PRIVATE\_IPV4\_IN\_USED            | Private IPv4 is occupied.                                    |
| 400              | INVALID\_VPC\_SECURITY\_GROUP\_ABSENT               | The specified VPC is not associated with any security group. |
| 400              | INVALID\_IP\_OUT\_OF\_RANGE                         | Invalid IP address. It does not belong to the CIDR block.    |
| 400              | INVALID\_IP\_FIRST\_ADDRESS                         | The IP address cannot be a gateway address.                  |
| 400              | INVALID\_IP\_NETWORK\_ADDRESS                       | The IP address cannot be a network address.                  |
| 400              | INVALID\_IP\_BROADCAST\_ADDRESS                     | The IP address cannot be a broadcast address.                |
