> 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/cn/bmc/load-balancing/createloadbalancer.md).

# CreateLoadBalancer

## 1. 接口描述

本接口(CreateLoadBalancer)用于创建负载均衡实例。

#### 准备工作

* 查询创建负载均衡的可用区：调用 [DescribeLoadBalancerZones](/api-reference/cn/bmc/load-balancing/describeloadbalancerzones.md) 接口。
* 查询区域负载均衡IP能否创建：调用 [DescribeLoadBalancerIPv4](https://github.com/zenlayer/zenlayercloud-api-doc-cn/tree/main/bmc/load-balancing/describeloadbalanceripv4.md) 或 [DescribeLoadBalancerIPv6](https://github.com/zenlayer/zenlayercloud-api-doc-cn/tree/main/bmc/load-balancing/describeinstances.md) 接口。
* 查询区域负载均衡规格能否创建：调用 [DescribeLoadBalancerSpecs](/api-reference/cn/bmc/load-balancing/describeloadbalancerspecs.md) 接口。
* 成本估算：了解负载均衡的计费方式。更多详情，请参见[计费方式概述](https://docs.console.zenlayer.com/welcome/pricing/bare-metal-cloud-pricing/billing-method)。

{% hint style="info" %}
**注意事项**

* 创建预付费负载均衡实例的购买会预先扣除本次实例购买所需金额，如果余额不足，请求将会失败。后付费实例购买时需要确保账户账号状态正常。
* 调用本接口创建负载均衡实例，支持代金券自动抵扣，详情请参考代金券选用规则。
  {% endhint %}

## 2. 请求参数

以下请求参数列表仅列出了接口中需要的请求参数

| 参数名称                  | 必选 | 类型                                                                      | 描述                                                                            |
| --------------------- | -- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| zoneId                | 是  | String                                                                  | 可用区的节点ID。                                                                     |
| loadBalancerName      | 是  | String                                                                  | 负载均衡名称。                                                                       |
| chargeType            | 是  | [ChargeType](/api-reference/cn/bmc/datastructure.md#chargetype)         | <p>付费类型。</p><p>PREPAID：预付费，即包年包月 POSTPAID：后付费。</p>                            |
| bandwidth             | 是  | Integer                                                                 | <p>带宽值。</p><p>取值范围：1-1024。</p><p>单位：Mbps</p><p>可选值范围：\[1, 10240]</p>          |
| ipType                | 是  | String                                                                  | <p>指定负载均衡绑定的IP的类型:</p><p>可用值：</p><ul><li>IPv4</li><li>IPv6</li></ul>          |
| clientToken           | 否  | String                                                                  | 用于保证请求的幂等性。                                                                   |
| instanceChargePrepaid | 否  | [ChargePrepaid](/api-reference/cn/bmc/datastructure.md#chargeprepaid)   | <p>预付费模式。</p><p>即包年包月相关参数设置。通过该参数可以指定包年包月实例的购买时长等属性。若指定实例的付费模式为预付费则该参数必传。</p> |
| vipCount              | 否  | Integer                                                                 | <p>额外购买VIP数量。</p><p>负载均衡会默认绑定1个指定类型的IP。</p>                                   |
| subnetId              | 否  | String                                                                  | <p>子网ID。</p><p>若是创建VIP4类型时，必须指定子网ID。该实例的主备IP将在该子网中获取。</p>                     |
| cidrBlockId           | 否  | String                                                                  | <p>CIDR ID。</p><p>创建VIP6类型时需要指定CIDR ID。如果该可用区中存在唯一一个CIDR则可以不指定，默认使用该CIDR。</p> |
| masterIp              | 否  | String                                                                  | 主IP。                                                                          |
| backupIp              | 否  | String                                                                  | 备IP。                                                                          |
| marketingOptions      | 否  | [MarketingInfo](/api-reference/cn/bmc/datastructure.md#marketinginfo)   | 市场营销活动相关信息。                                                                   |
| tags                  | 否  | [TagAssociation](/api-reference/cn/bmc/datastructure.md#tagassociation) | <p>创建负载均衡时关联的标签。</p><p>注意: 关联标签键不能重复。</p>                                     |

## 3. 响应结果

| 参数名称           | 类型     | 描述                                                       |
| -------------- | ------ | -------------------------------------------------------- |
| requestId      | String | <p>唯一请求 ID。</p><p>每次请求都会返回。定位问题时需要提供该次请求的 requestId。</p> |
| orderNumber    | String | 订单号。                                                     |
| loadBalancerId | String | 负载均衡ID。                                                  |

## 4. 代码示例

{% tabs %}
{% tab title="示例" %}

1. **创建负载均衡实例。**

```json
POST /api/v2/bmc HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreateLoadBalancer
Request:
{
  "zoneId": "HKG-A",
  "loadBalancerName": "xxxx",
  "specName": "xxxx",
  "clientToken": "xxxx",
  "chargeType": "xxxx",
  "bandwidth": 100,
  "subnetId": "xxxx",
  "ipType": "IPv4"
}
Response:
{
  "requestId": "TEEFDCA5B-76FB-4E91-A18E-DF7F5D2CE41F",
  "response": {
    "requestId": "TEEFDCA5B-76FB-4E91-A18E-DF7F5D2CE41F",
    "orderNumber": "xxxx",
    "loadBalancerId": "xxxx"
  }
}
```

{% endtab %}
{% endtabs %}

## 5. 开发者工具

Zenlayer Cloud API 2.0 提供了配套的[开发工具集（SDK）](/api-reference/cn/api-introduction/toolkit.md)，未来会陆续支持更多开发语言，方便快速接入和使用Zenlayer的产品和服务。

## 6. 错误码

下面包含业务逻辑中遇到的错误码，其他错误码见[公共错误码](/api-reference/cn/api-introduction/instruction/commonerrorcode.md)

| HTTP状态码 | 错误码 | 说明 |
| ------- | --- | -- |
