# 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。
  {% 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>                                                                                                   |
| 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)                         | <p>主公网IP的运营商。</p><p>该字段仅作用于三线IP(<code>ThreeLine</code>)。</p>                                                                                         |
| 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>从CIDR里指定公网起始IP地址开始创建弹性IP。</p><p>该字段仅在指定<code>cidrId</code>时生效。</p>                                                                                |
| resourceGroupId    | 否  | String                                                                                  | 弹性公网IP所放的资源组ID，如不指定则放入默认资源组。                                                                                                                         |
| flowPackage        | 否  | Float                                                                                   | <p>公网IPv6的流量包大小。</p><p>单位为TB。</p><p>值要求为0或0.1的倍数。</p><p>当子网的堆栈类型包括V6且为公网时，且网络计费方式是流量计费(<code>ByTrafficPackage</code>)需要指定。</p><p>可选值范围：\[0.0, +)</p> |
| clusterId          | 否  | String                                                                                  | <p>公网IPv6所指定的共享带宽包ID。</p><p>当子网的堆栈类型包括V6且为公网时，且网络计费方式是共享带宽包计费(<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>                                                                                               |
| instanceIds        | 否  | Array of String                                                                         | <p>要绑定的实例ID集合。</p><p>数量需要与<code>amount</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>默认值：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
}
```

**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. 创建一个`Remote IP`,远端节点为`asia-southwest-1`, 使用共享带宽包计费。**

```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-RemoteIP",
  "internetChargeType": "BandwidthCluster",
  "networkLineType": "PremiumBGP",
  "bandwidth": 50,
  "clusterId": "<clusterId>",
  "resourceGroupId": "xxxx",
  "peerRegionId": "asia-southwest-1"
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "eipIds": ["<eipId>"],
    "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地址段不存在。            |
| 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     | 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     | OPERATION\_DENIED\_EIP\_NOT\_SUPPORT\_PASS\_THROUGH\_BIND\_TYPE | EIP模式不支持高速模式。          |
| 400     | INVALID\_REGION\_MISMATCH                                       | 区域不匹配。                 |
| 400     | OPERATION\_DENIED\_EIP\_INSTANCE\_NOT\_ADAPTER                  | 指定的实例数量与需要创建的EIP数量不一致。 |
| 404     | INVALID\_INSTANCE\_NOT\_FOUND                                   | 服务器实例不存在。              |
| 400     | INVALID\_NIC\_STATUS                                            | 当前网卡状态无法进行操作。          |
| 400     | OPERATION\_DENIED\_LAN\_EIP\_TYPE\_CONFLICTS                    | 内网IP上的公网Ipv4类型冲突。      |
| 400     | OPERATION\_DENIED\_EIP\_ASSIGNED\_LIMIT\_EXCEEDED               | EIP绑定超过数量限制。           |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/api-reference/cn/compute/zec/elastic-ip/createeips.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
