> 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/compute/zec/elastic-ip/createeips.md).

# CreateEips

## 1. 接口描述

本接口(CreateEips)用于创建弹性公网IP。

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

* 可以通过调用[`DescribeEipRegions`](/api-reference/cn/compute/zec/elastic-ip/describeeipregions.md) 来查询支持弹性IP的区域。
* 可以通过调用 [`DescribeEipInternetChargeTypes`](/api-reference/cn/compute/zec/elastic-ip/describeeipinternetchargetypes.md) 来查询公网IP支持的网络计费方式。
* 如果需要创建`Remote EIP`,可以先查询[`DescribeEipRemoteRegions`](/api-reference/cn/compute/zec/elastic-ip/describeeipremoteregions.md)来查询支持远端节点。
* 如果需要通过`CIDR`进行分配，可以先查询[`DescribeCidrs`](/api-reference/cn/compute/zec/cidr-block/describecidrs.md)来查询账号下的`CIDR`。
* 如果同时绑定实例，需要保证所选实例的`主网卡`上的`主内网IP`还能再分配EIP。
* 指定`prefixLength`小于32时创建EIP Block资源，同时绑定实例时`bindType`只能为`Passthrough`。
* 指定`publicIp`时，`prefixLength`为32表示指定纯IPv4起始地址，小于32时表示指定带掩码的起始网段（掩码须与`prefixLength`一致，如`88.0.5.64/26`）。指定`cidrId`时，该起始地址/网段必须是所选`CIDR`当前可分配的候选之一；不指定`cidrId`时（仅支持`prefixLength`为32），从公网IP池按此地址开始顺序分配。
* 保底流量包大小仅对计费周期为月有效。
  {% endhint %}

## 2. 请求参数

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

| 参数名称               | 必选 | 类型                                                                                      | 描述                                                                                                                                                                                                                                                                                                                          |
| ------------------ | -- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| regionId           | 是  | String                                                                                  | 创建EIP所在的节点ID。                                                                                                                                                                                                                                                                                                               |
| name               | 是  | String                                                                                  | <p>EIP的名称。</p><p>范围2到63个字符。</p><p>仅支持输入字母、数字、-/\_和英文句点(.)。</p><p>且必须以数字或字母开头和结尾。</p>                                                                                                                                                                                                                                        |
| internetChargeType | 是  | [InternetChargeType](/api-reference/cn/compute/zec/datastructure.md#internetchargetype) | 公网弹性IP的网络计费方式。                                                                                                                                                                                                                                                                                                              |
| amount             | 否  | Integer                                                                                 | <p>需要创建EIP的数量。</p><p>可选值范围：\[1, +)</p><p>默认值：1</p>                                                                                                                                                                                                                                                                          |
| prefixLength       | 否  | Integer                                                                                 | <p>掩码长度，取值范围20–32，默认32。</p><p>指定小于32时，创建EIP Block资源，必须同时指定<code>cidrId</code>，且不能小于所选CIDR自身的掩码长度。</p><p>可选值范围：\[20, 32]</p><p>默认值：32</p>                                                                                                                                                                                    |
| eipV4Type \[已废弃]   | 否  | [EipNetworkType](/api-reference/cn/compute/zec/datastructure.md#eipnetworktype)         | <p>公网弹性IP的线路类型。</p><p>已废弃，请使用<code>networkLineType</code>。</p>                                                                                                                                                                                                                                                              |
| networkLineType    | 否  | [NetworkLineType](/api-reference/cn/compute/zec/datastructure.md#networklinetype)       | 公网弹性IP的线路类型。                                                                                                                                                                                                                                                                                                                |
| primaryIsp \[已废弃]  | 否  | [EipIsp](/api-reference/cn/compute/zec/datastructure.md#eipisp)                         | 主公网IP的运营商。                                                                                                                                                                                                                                                                                                                  |
| bandwidth          | 否  | Integer                                                                                 | <p>公网弹性IP的带宽限速。</p><p>单位：Mbps。</p><p>可选值范围：\[1, +)</p>                                                                                                                                                                                                                                                                      |
| cidrId             | 否  | String                                                                                  | <p>指定CIDR ID，使用CIDR内分配弹性IP。</p><p>该字段和<code>eipV4Type</code>不能同时指定。</p>                                                                                                                                                                                                                                                     |
| publicIp           | 否  | String                                                                                  | <p>指定公网起始地址开始创建弹性IP。</p><p>不指定<code>cidrId</code>时，从公网IP池按此地址开始顺序分配（仅支持<code>prefixLength</code>为32）；指定<code>cidrId</code>时，从该CIDR内按此地址开始分配。</p><p><code>prefixLength</code>为32时填纯IPv4地址；<code>prefixLength</code>小于32时必须同时指定<code>cidrId</code>，填带掩码的起始网段（掩码须与<code>prefixLength</code>一致，如<code>88.0.5.64/26</code>）。</p> |
| resourceGroupId    | 否  | String                                                                                  | 弹性公网IP所放的资源组ID，如不指定则放入默认资源组。                                                                                                                                                                                                                                                                                                |
| flowPackage        | 否  | Float                                                                                   | <p>弹性公网IP的流量包大小。</p><p>单位为TB。</p><p>值要求为0或0.1的倍数。</p><p>当网络计费方式为流量计费(<code>ByTrafficPackage</code>)时需要指定。</p><p>可选值范围：\[0.0, +)</p>                                                                                                                                                                                         |
| clusterId          | 否  | String                                                                                  | <p>共享带宽包ID。</p><p>当网络计费方式为共享带宽包计费(<code>BandwidthCluster</code>)时需要指定。</p>                                                                                                                                                                                                                                                  |
| peerRegionId       | 否  | String                                                                                  | 远端的节点ID。                                                                                                                                                                                                                                                                                                                    |
| marketingOptions   | 否  | [MarketingInfo](/api-reference/cn/compute/zec/datastructure.md#marketinginfo)           | 市场营销的相关选项。                                                                                                                                                                                                                                                                                                                  |
| tags               | 否  | [TagAssociation](/api-reference/cn/compute/zec/datastructure.md#tagassociation)         | <p>弹性公网IP绑定的标签。</p><p>注意：实例关联<code>标签键</code>不能重复。</p>                                                                                                                                                                                                                                                                      |
| instanceId         | 否  | String                                                                                  | <p>要绑定的实例ID。</p><p>本批次创建的EIP全部绑定到该实例。</p>                                                                                                                                                                                                                                                                                   |
| instanceIds        | 否  | Array of String                                                                         | <p>要绑定的实例ID集合。</p><p>数量需要与<code>amount</code>字段一致，每个EIP各绑定一个不同实例；与<code>instanceId</code>同时传递时以<code>instanceId</code>为准。</p>                                                                                                                                                                                               |
| bindType           | 否  | [BindType](/api-reference/cn/compute/zec/datastructure.md#bindtype)                     | <p>绑定类型。</p><p>当指定<code>instanceIds</code>时生效。</p><p>默认为普通NAT模式。</p>                                                                                                                                                                                                                                                        |
| rateLimitMode      | 否  | [RateLimitMode](/api-reference/cn/compute/zec/datastructure.md#ratelimitmode)           | <p>限速模式。</p><p><code>STRICT</code>严格模式必须同时指定<code>bandwidth</code>。</p><p>默认值：LOOSE</p>                                                                                                                                                                                                                                     |

## 3. 响应结果

| 参数名称        | 类型              | 描述                                                       |
| ----------- | --------------- | -------------------------------------------------------- |
| requestId   | String          | <p>唯一请求 ID。</p><p>每次请求都会返回。定位问题时需要提供该次请求的 requestId。</p> |
| eipIds      | Array of String | 创建的弹性公网IP ID列表。                                          |
| orderNumber | String          | 本次创建的订单编号。                                               |

## 4. 代码示例

{% tabs %}
{% tab title="示例" %}
**1. 创建一个BGP线路的公网弹性IP, 使用流量包计费。流量包大小为10TB。带宽限速为50Mbps。**

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

Request：
{
  "regionId": "asia-east-1",
  "amount": 1,
  "name": "Test-EIP",
  "internetChargeType": "ByTrafficPackage",
  "networkLineType": "PremiumBGP",
  "bandwidth": 50,
  "flowPackage": 10,
  "rateLimitMode": "LOOSE"
}
```

**2. 从CIDR里分配2个公网弹性IP, 使用固定带宽计费。带宽限速为50Mbps。**

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

Request：
{
  "regionId": "asia-east-1",
  "amount": 2,
  "name": "Test-EIP",
  "internetChargeType": "ByBandwidth",
  "cidrId": "<cidrId>",
  "bandwidth": 50
}
  
Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "eipIds": ["<eipId>", "<eipId2>"],
    "orderNumber": "<orderNumber>"
  }
}
```

**3. 从BYOIP的`CIDR`（如`128.0.0.0/24`）里分配单个`/32`的弹性IP并绑定实例。`prefixLength`默认为32，可以省略；NAT模式（默认）与`Passthrough`模式均支持。**

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

Request：
{
  "regionId": "na-east-1",
  "amount": 1,
  "name": "Test-EIP",
  "internetChargeType": "BandwidthCluster",
  "clusterId": "<clusterId>",
  "cidrId": "<cidrId>",
  "prefixLength": 32,
  "instanceIds": ["<instanceId>"],
  "bindType": "FullNat"
}

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

**4. 从掩码为`/24`的BYOIP `CIDR`里分配一个`/24`的弹性IP（EIP Block）并绑定实例。`/24`的BYOIP `CIDR`只能分配出一个`/24`的EIP，因此`amount`只能为1。EIP Block（`prefixLength`小于32）只支持`Passthrough`绑定模式，不支持NAT模式。**

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

Request：
{
  "regionId": "na-east-1",
  "amount": 1,
  "name": "Test-EIP",
  "internetChargeType": "BandwidthCluster",
  "clusterId": "<clusterId>",
  "cidrId": "<cidrId>",
  "prefixLength": 24,
  "instanceIds": ["<instanceId>"],
  "bindType": "Passthrough"
}

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

**5. 创建3个公网弹性IP，全部绑定到同一台实例上（`instanceId`）。**

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

Request：
{
  "regionId": "asia-east-1",
  "amount": 3,
  "name": "Test-EIP",
  "internetChargeType": "ByBandwidth",
  "networkLineType": "PremiumBGP",
  "bandwidth": 50,
  "instanceId": "<instanceId>"
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "eipIds": ["<eipId1>", "<eipId2>", "<eipId3>"],
    "orderNumber": "<orderNumber>"
  }
}
```

**6. 创建2个公网弹性IP，每个各绑定一台不同的实例（`instanceIds`，数量需与`amount`一致）。**

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

Request：
{
  "regionId": "asia-east-1",
  "amount": 2,
  "name": "Test-EIP",
  "internetChargeType": "ByBandwidth",
  "networkLineType": "PremiumBGP",
  "bandwidth": 50,
  "instanceIds": ["<instanceId1>", "<instanceId2>"]
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "eipIds": ["<eipId1>", "<eipId2>"],
    "orderNumber": "<orderNumber>"
  }
}
```

{% 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状态码 | 错误码                                                                   | 说明                                         |
| ------- | --------------------------------------------------------------------- | ------------------------------------------ |
| 404     | INVALID\_CIDR\_NOT\_FOUND                                             | CIDR地址段不存在。                                |
| 404     | INVALID\_CIDR\_IP\_NOT\_FOUND                                         | 指定的IP地址在CIDR中不存在。                          |
| 400     | INVALID\_PREFIX\_LENGTH\_OUT\_OF\_RANGE                               | EIP掩码长度不合法。                                |
| 400     | INVALID\_PREFIX\_LENGTH\_MUST\_EXCEED\_CIDR\_NETMASK                  | EIP掩码长度必须大于所选 CIDR 的掩码长度。                  |
| 400     | INVALID\_STARTING\_CIDR\_PREFIX\_MISMATCH                             | 指定的起始网段掩码长度和 prefixLength 不一致。             |
| 400     | INVALID\_PARAMETER\_BANDWIDTH\_ERROR                                  | 带宽限速值超过最小限制。                               |
| 400     | INVALID\_RATE\_LIMIT\_MODE\_REQUIRES\_BANDWIDTH                       | 限速模式为STRICT时必须指定带宽。                        |
| 400     | OPERATION\_DENIED\_CIDR\_CREATE\_SOURCE                               | 该CIDR来源不支持此操作。                             |
| 400     | INVALID\_PARAMETER\_BANDWIDTH\_EXCEED                                 | 带宽限速值超过最大限制。                               |
| 404     | INVALID\_REGION\_NOT\_FOUND                                           | 区域不存在。                                     |
| 400     | OPERATION\_DENIED\_CIDR\_IP\_INSUFFICIENT                             | CIDR剩余IP不足。                                |
| 400     | OPERATION\_DENIED\_CIDR\_STATUS                                       | 指定的CIDR状态不支持该操作。                           |
| 400     | OPERATION\_DENIED\_EIP\_UNSUPPORTED\_CUSTOMIZE                        | 手动指定的IP地址不合法。                              |
| 400     | INVALID\_IP\_NETWORK\_ADDRESS                                         | IP为网络地址不可用。                                |
| 400     | INVALID\_IP\_BROADCAST\_ADDRESS                                       | IP为广播地址不可用。                                |
| 400     | OPERATION\_DENIED\_EIP\_UNSUPPORTED\_NETWORK\_TYPE                    | EIP网络计费方式不支持。                              |
| 400     | OPERATION\_DENIED\_EIP\_UNSUPPORTED\_REMOTE\_IPT                      | 该客户暂时不支持配置Remote IPT。                      |
| 400     | OPERATION\_DENIED\_INTERNET\_CHARGE\_TYPE\_NOT\_SUPPORT               | IP网络计费方式不支持。                               |
| 400     | INVALID\_REGION\_MISMATCH                                             | EIP与目标资源不在同一区域。                            |
| 400     | OPERATION\_DENIED\_EIP\_INSTANCE\_NOT\_ADAPTER                        | 指定的实例数量与需要创建的EIP数量不一致。                     |
| 404     | INVALID\_INSTANCE\_NOT\_FOUND                                         | 服务器实例不存在。                                  |
| 400     | INVALID\_NIC\_STATUS                                                  | 当前网卡状态无法进行操作。                              |
| 400     | OPERATION\_DENIED\_EIP\_ASSIGNED\_LIMIT\_EXCEEDED                     | EIP绑定超过数量限制。                               |
| 400     | OPERATION\_DENIED\_FLOW\_PACKAGE\_NOT\_SUPPORTED\_HOUR\_PERIOD        | 当前产品周期为小时计费，不支持设置保底流量包大小。                  |
| 400     | INVALID\_PARAMETER\_FLOW\_PACKAGE\_NOT\_SUPPORTED\_FOR\_PATH\_BASED   | PathBasedBandwidthIP 不支持自定义流量包大小，需传 0 或不传。 |
| 400     | OPERATION\_DENIED\_FIXED\_BANDWIDTH\_NOT\_SUPPORTED\_FOR\_PATH\_BASED | PathBasedBandwidthIP 不支持固定带宽计费。            |
| 400     | INVALID\_EIP\_BINDING\_MODE\_UNSUPPORTED                              | EIP Block不支持NAT绑定模式。                       |
