> 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/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**

* If `ipAddress` is not specified, the system automatically assigns a private IP from the subnet CIDR range.
* If `ipAddress` is specified, it must be within the subnet CIDR range and must not be a gateway address or an address already in use.
* If `securityGroupId` is not specified, the default security group of the VPC is used.
* Each team can create up to 10 HaVips (default quota). If you need to create more, please 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                                                                       | The ID of the subnet to which the HaVip belongs.                                          |
| name            | Yes      | String                                                                       | HaVip name. Length: 1 to 64 characters.                                                   |
| ipAddress       | No       | String                                                                       | Private IP address for the HaVip. If not specified, the system automatically assigns one. |
| securityGroupId | No       | String                                                                       | Security group ID. If not specified, the default security group of the VPC is used.       |
| tags            | No       | [TagAssociation](/api-reference/compute/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.                |
