> 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/zlb/load-balancer-instance/createloadbalancer.md).

# CreateLoadBalancer

## 1. API Description

This API (CreateLoadBalancer) is used to create a load balancer instance.

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

* You can call [DescribeLoadBalancerRegions](/api-reference/zlb/location/describeloadbalancerregions.md) to check the regions that support purchasing load balancers.
* This API is asynchronous. After the request returns successfully, you can call [DescribeLoadBalancers](/api-reference/zlb/load-balancer-instance/describeloadbalancers.md) to query the state of the load balancer instance. A state of `RUNNING` indicates that the instance was created successfully.
* Currently, load balancer instances can only be created for ZEC servers.
* Only postpaid load balancer instances can be created.
* When creating a load balancer instance, make sure that the VPC has a subnet meeting the `ipStackType` requirement and that at least 2 addresses in the subnet are available for allocation.
* When an existing EIP is specified through `eipIds`, the EIP is associated only after the load balancer instance is created (its state becomes `RUNNING`). You can call [DescribeEips](/api-reference/zec/elastic-ip/describeeips.md) to query the association result.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name              | Required | Type                                                                                   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| --------------------------- | -------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| regionId                    | Yes      | String                                                                                 | <p>Region ID.</p><p>It can be obtained by calling <a href="/api-reference/zec/location/describeregions.md">DescribeRegions</a>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| loadBalancerName            | Yes      | String                                                                                 | <p>Load balance instance name.</p><p>Containing 1 to 64 characters.</p><p>Available range: \[1.0, +).</p><p>Value range: \[1.0, +)</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| vpcId                       | No       | String                                                                                 | <p>ID of the VPC to which the backend servers of the load balancer belong.</p><p>At least one of <code>vpcId</code> and <code>subnetId</code> must be specified.</p><p>If only <code>subnetId</code> is specified, the VPC to which the subnet belongs is used.</p><p>It can be obtained by calling <a href="/api-reference/zec/vpc-network/describevpcs.md">DescribeVpcs</a>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| subnetId                    | No       | String                                                                                 | <p>Subnet ID.</p><p>It can be obtained by calling <a href="/api-reference/zec/vpc-network/describesubnets.md">DescribeSubnets</a>.</p><p>At least one of <code>vpcId</code> and <code>subnetId</code> must be specified.</p><p>The subnet must be in the same region as <code>regionId</code>; if <code>vpcId</code> is also specified, the subnet must belong to that VPC.</p><p>When <code>ipStackType</code> is <code>IPv4</code>, the subnet must support IPv4 and this parameter is optional (the system selects one within the VPC). When <code>ipStackType</code> is <code>IPv6</code>, the subnet must contain a public IPv6 block (a private IPv6 block does not qualify) and <strong>this parameter is required</strong>: both the public IPv6 VIP and the health check block are allocated from this subnet, and <code>MISSING\_PARAMETER</code> is returned if it is not specified.</p>                                                                                                                                    |
| healthCheckPrivateIps       | No       | Array of String                                                                        | <p>Health probe source private IP addresses; the quantity must be 2.</p><p>When <code>subnetId</code> is specified and this field is left empty, 2 available private IPv4 addresses are randomly allocated from that subnet as the health probe source IPs. Each load balancer instance occupies 2 addresses; if the subnet does not have enough available private IPv4 addresses remaining, <code>INVALID\_SUBNET\_IPV4\_INSUFFICIENT</code> is returned. The allocation result can be queried by calling <a href="/api-reference/zlb/load-balancer-instance/describeloadbalancers.md">DescribeLoadBalancers</a>.</p><p>When <code>subnetId</code> is not specified, this parameter is invalid.</p><p>It can be specified only when <code>ipStackType</code> is <code>IPv4</code>. When <code>ipStackType</code> is <code>IPv6</code>, the health probe block is automatically allocated by the system from the public IPv6 block of the subnet, and specifying this parameter returns <code>INVALID\_PARAMETER\_CONFLICT</code>.</p> |
| ipStackType                 | No       | [LoadBalancerIpStackType](/api-reference/zlb/datastructure.md#loadbalanceripstacktype) | <p>IP stack type.</p><p>A load balancer instance supports only a single stack, that is, <code>IPv4</code> or <code>IPv6</code>. Dual stack is not supported.</p><p>When <code>IPv6</code> is specified, the public network parameters (<code>internetChargeType</code>, <code>networkLineType</code>, <code>bandwidthMbps</code>, <code>trafficPackageSize</code>, <code>bandwidthClusterId</code>) cannot be configured, and <code>eipIds</code> cannot be specified either, because all EIPs are IPv4. The public addresses of an IPv6 load balancer are assigned separately through <a href="/api-reference/zlb/load-balancer-instance/assignloadbalanceripv6.md">AssignLoadBalancerIpv6</a>.</p><p>Default value: IPv4</p>                                                                                                                                                                                                                                                                                                         |
| eipIds                      | No       | Array of String                                                                        | <p>List of IDs of existing elastic IPs to be associated with the new load balancer instance.</p><p>Both single-IP EIPs (mask <code>/32</code>) and block-type EIPs are supported. You can call <a href="/api-reference/zec/elastic-ip/describeeips.md">DescribeEips</a> to query them.</p><p>All EIPs must be in the same region as <code>regionId</code> and in the unassociated state.</p><p>When this parameter is specified, <code>internetChargeType</code>, <code>networkLineType</code>, <code>bandwidthMbps</code>, <code>trafficPackageSize</code>, and <code>bandwidthClusterId</code> do not take effect, no new EIP is created for the instance, and <code>number</code> can only be 1.</p><p>It can be specified only when <code>ipStackType</code> is <code>IPv4</code>.</p>                                                                                                                                                                                                                                             |
| internetChargeType          | No       | [InternetChargeType](/api-reference/zlb/datastructure.md#internetchargetype)           | <p>IP network billing model.</p><p>This parameter does not take effect when <code>eipIds</code> is specified.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ipNetworkType \[Deprecated] | No       | [EipNetworkType](/api-reference/zlb/datastructure.md#eipnetworktype)                   | <p>IP network type.</p><p>Deprecated. Use <code>networkLineType</code> instead.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| networkLineType             | No       | [NetworkLineType](/api-reference/zlb/datastructure.md#networklinetype)                 | IP network type.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| bandwidthMbps               | No       | Integer                                                                                | <p>Maximum outbound bandwidth of the elastic IP. Unit: Mbps. The maximum limit is usually 10000 Mbps. If you have additional requirements, please contact Support. This parameter is required when <code>internetChargeType</code> is <code>ByBandwidth</code>.</p><p>Value range: \[1, +)</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| trafficPackageSize          | No       | Float                                                                                  | <p>Traffic package size.</p><p>When this parameter is specified, the IP network billing method (<code>internetChargeType</code>) must be <code>ByTrafficPackage</code>; otherwise this parameter does not take effect.</p><p>It can only be set when the billing period is monthly; hourly billing is not supported.</p><p>Value range: \[0.0, 999999.0]</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| bandwidthClusterId          | No       | String                                                                                 | <p>Bandwidth cluster ID.</p><p>When this parameter is specified, the IP network billing method (<code>internetChargeType</code>) must be <code>BandwidthCluster</code>; otherwise this parameter does not take effect.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| resourceGroupId             | No       | String                                                                                 | <p>Resource Group ID</p><p>If not specified, the load balance instance will belong to the default resource group.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| number                      | No       | Integer                                                                                | <p>The number of created load balancers.</p><p>Default value: 1</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| marketingOptions            | No       | [MarketingInfo](/api-reference/zlb/datastructure.md#marketinginfo)                     | Information on marketing campaigns.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| tags                        | No       | [TagAssociation](/api-reference/zlb/datastructure.md#tagassociation)                   | <p>Bound tags when creating the load balancer.</p><p>Tag keys must be unique.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| securityGroupId             | No       | String                                                                                 | <p>ID of the security group associated with the load balancer instance.</p><p>It can be obtained by calling <a href="/api-reference/zec/security-group/describesecuritygroups.md">DescribeSecurityGroups</a>.</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> |
| orderNumber     | String          | Order number.                                                                                                         |
| loadBalancerIds | Array of String | A collection of unique IDs of the load balancer instances.                                                            |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**1. Create a public load balancer instance. The IP billing method is fixed bandwidth.**

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

Request:
{
  "regionId" : "asia-east-1",
  "vpcId" : "<vpcId>",
  "securityGroupId" : "<securityGroupId>",
  "loadBalancerName" : "sample",
  "internetChargeType" : "ByBandwidth",
  "networkLineType" : "PremiumBGP",
  "bandwidthMbps" : 2,
  "trafficPackageSize" : null,
  "bandwidthClusterId" : "",
  "number" : 1
}

Response:
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "orderNumber": "<orderNumber>",
    "loadBalancerIds": ["<loadBalancerId>"]
  }
}
```

**2. Specify only `subnetId` without `vpcId`: the load balancer instance belongs to the VPC of the subnet, and 2 private IPv4 addresses are randomly allocated from the subnet as the health check source IPs.**

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

Request:
{
  "regionId" : "asia-east-1",
  "subnetId" : "<subnetId>",
  "loadBalancerName" : "sample",
  "internetChargeType" : "ByBandwidth",
  "networkLineType" : "PremiumBGP",
  "bandwidthMbps" : 2,
  "number" : 1
}

Response:
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "orderNumber": "<orderNumber>",
    "loadBalancerIds": ["<loadBalancerId>"]
  }
}
```

**3. Create a load balancer instance with an existing elastic IP (EIP) instead of creating a new EIP.**

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

Request:
{
  "regionId" : "asia-east-1",
  "vpcId" : "<vpcId>",
  "loadBalancerName" : "sample",
  "eipIds" : ["<eipId1>", "<eipId2>"],
  "number" : 1
}

Response:
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "orderNumber": "<orderNumber>",
    "loadBalancerIds": ["<loadBalancerId>"]
  }
}
```

**4. Create a load balancer instance with a POC voucher. If no POC voucher exists in the system, the creation will fail.**

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

Request:
{
  "regionId" : "asia-east-1",
  "vpcId" : "<vpcId>",
  "securityGroupId" : "<securityGroupId>",
  "loadBalancerName" : "sample",
  "internetChargeType" : "ByBandwidth",
  "networkLineType" : "PremiumBGP",
  "bandwidthMbps" : 2,
  "number" : 1,
  "marketingOptions" : {
    "usePocVoucher" : true
  }
}

Response:
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "orderNumber": "<orderNumber>",
    "loadBalancerIds": ["<loadBalancerId>"]
  }
}
```

{% 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\_EIP\_NOT\_FOUND                                              | Elastic IP does not exist.                                                                                     |
| 400              | INVALID\_IP\_BROADCAST\_ADDRESS                                       | Invalid IP address: broadcast addresses are not allowed.                                                       |
| 400              | INVALID\_IP\_FIRST\_ADDRESS                                           | Invalid IP address: gateway addresses are not allowed.                                                         |
| 400              | INVALID\_IP\_NETWORK\_ADDRESS                                         | Invalid IP address: network addresses are not allowed.                                                         |
| 400              | INVALID\_IP\_OUT\_OF\_RANGE                                           | Invalid IP address: not within the CIDR range.                                                                 |
| 400              | INVALID\_REGION\_MISMATCH                                             | The EIP is not in the same region as the target resource.                                                      |
| 404              | INVALID\_REGION\_NOT\_FOUND                                           | Specified region does not exist.                                                                               |
| 404              | INVALID\_SECURITY\_GROUP\_NOT\_FOUND                                  | Security group does not exist.                                                                                 |
| 409              | INVALID\_SUBNET\_IPV4\_INSUFFICIENT                                   | There are not enough available IPv4 addresses in the subnet.                                                   |
| 409              | INVALID\_SUBNET\_IPV6\_INSUFFICIENT                                   | The number of the available IPv6 addresses in the subnet is insufficient.                                      |
| 400              | INVALID\_SUBNET\_NOT\_BELONG\_TO\_VPC                                 | Specified subnet is not within the global VPC.                                                                 |
| 404              | INVALID\_SUBNET\_NOT\_FOUND                                           | Subnet does not exist.                                                                                         |
| 409              | INVALID\_SUBNET\_PRIVATE\_IPV4\_IN\_USED                              | Preset private IP is already be used.                                                                          |
| 404              | INVALID\_VPC\_NOT\_FOUND                                              | Global VPC does not exist.                                                                                     |
| 400              | OPERATION\_DENIED\_EIP\_ASSIGNED\_LIMIT\_EXCEEDED                     | Elastic IP binding exceeds the allowed limit.                                                                  |
| 400              | OPERATION\_DENIED\_EIP\_INSUFFICIENT                                  | Insufficient elastic IP addresses. Operation failed.                                                           |
| 400              | OPERATION\_DENIED\_EIP\_IS\_DEFAULT                                   | Default public IP cannot be unbound.                                                                           |
| 400              | OPERATION\_DENIED\_EIP\_IS\_NOT\_UN\_ASSIGN                           | The EIP is already occupied (not in the unbound state) and cannot be bound.                                    |
| 400              | OPERATION\_DENIED\_EIP\_QUOTA\_LIMIT\_EXCEEDED                        | The number of elastic IP addresses exceeds limit.                                                              |
| 500              | OPERATION\_DENIED\_EIP\_STATUS\_NOT\_SUPPORT                          | The current EIP status does not support this operation.                                                        |
| 400              | OPERATION\_DENIED\_SUBNET\_TYPE\_NOT\_SUPPORT                         | Subnet stack type is not supported.                                                                            |
| 400              | OPERATION\_DENIED\_SUBNET\_TYPE\_NOT\_SUPPORT\_IPV4                   | IPv4 subnet stack type is not supported.                                                                       |
| 400              | OPERATION\_DENIED\_SUBNET\_NOT\_SUPPORT\_PUBLIC\_IPV6                 | The subnet does not have a public IPv6 block.                                                                  |
| 409              | OPERATION\_DENIED\_NO\_AVAILABLE\_SUBNET                              | No valid subnet exists under the global VPC. Operation failed.                                                 |
| 400              | INVALID\_PARAMETER\_FLOW\_PACKAGE\_NOT\_SUPPORTED\_FOR\_PATH\_BASED   | PathBasedBandwidthIP does not support a custom traffic package size. Pass 0 or omit this parameter.            |
| 400              | OPERATION\_DENIED\_FIXED\_BANDWIDTH\_NOT\_SUPPORTED\_FOR\_PATH\_BASED | PathBasedBandwidthIP does not support fixed bandwidth billing.                                                 |
| 400              | OPERATION\_DENIED\_FLOW\_PACKAGE\_NOT\_SUPPORTED\_HOUR\_PERIOD        | The current product cycle is based on hourly billing and does not support setting a minimum data package size. |
