# AllocateEipAddresses

## 1. API Description

This API (AllocateEipAddresses) is used to apply for one or multiple elastic IPs.

#### Prerequisites

* Query available elastic IPs in zone: call `DescribeEipAvailableResources` to check the stock of the specified zone.
* Cost estimation: know of the pricing model of elastic IPs. See [Elastic IP](https://docs.console.zenlayer.com/welcome/pricing/bare-metal-cloud-pricing/billing-method#elastic-ip) for details.

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>

* <mark style="color:blue;">If you create a subscription elastic IP, the amount required will be pre-deducted. If the balance is insufficient, the request will fail. If you create a pay-as-you-go elastic IP, please ensure your account balance is sufficient before calling this API.</mark>
* <mark style="color:blue;">Vouchers can be used for fee deduction in creation. See</mark> [<mark style="color:purple;">Vouchers</mark>](https://docs.console.zenlayer.com/welcome/platform/billing-center/vouchers) <mark style="color:purple;">for more details.</mark>
* <mark style="color:blue;">This API is an async API. An ID list is returned after the request is sent. However, it does not mean the creation has been completed. The status of the elastic IP will be or</mark> <mark style="color:blue;">`CREATING`</mark> <mark style="color:blue;">during the creation. You can use</mark> [<mark style="color:purple;">`DescribeEipAddresses`</mark>](/api-reference/compute/bmc/elastic-ip/describeeipaddresses.md) <mark style="color:blue;">to query the status of the elastic IP. If the status changes from</mark> <mark style="color:blue;">`Creating`</mark> <mark style="color:blue;">to</mark> <mark style="color:blue;">`Available`</mark><mark style="color:blue;">, it means that the elastic IP has been created successfully;</mark> <mark style="color:blue;">`CREATE_FAILED`</mark> <mark style="color:blue;">means the elastic IP has been created failed. Any operations on the elastic IPs are not allowed while creating.</mark>
* <mark style="color:blue;">A maximum of 100 elastic IPs can be created in one request.</mark>
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name   | Required | Type                                                                         | Description                                                                                                                                                                                     |
| ---------------- | -------- | ---------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| zoneId           | Yes      | String                                                                       | Zone ID to which the elastic IPs belong.                                                                                                                                                        |
| eipChargeType    | Yes      | [ChargeType](/api-reference/compute/bmc/datastructure.md#chargetype)         | <p>Elastic IP pricing model .</p><p>PREPAID: subscription</p><p>POSTPAID: pay-as-you-go</p>                                                                                                     |
| eipChargePrepaid | No       | [ChargePrepaid](/api-reference/compute/bmc/datastructure.md#chargeprepaid)   | Details of the monthly subscription, including the purchase period, auto-renewal. It is required if the eipChargeType is PREPAID .                                                              |
| resourceGroupId  | No       | String                                                                       | <p>Resource group ID</p><p>If the value is not passed in, the elastic IP will be put into the default resource group. If no authorized default resource group found, the request will fail.</p> |
| amount           | No       | Integer                                                                      | <p>Quantity of elastic IPs.</p><p>Value range: \[1, 100]</p><p>Default value: 1</p>                                                                                                             |
| netmask          | No       | Integer                                                                      | <p>The purchased netmask.</p><p>You can obtain the list of available netmasks from the DescribeEipAvailableResources API.</p><p>Value range: \[1, 32]</p><p>Default value: 32</p>               |
| marketingOptions | No       | [MarketingInfo](/api-reference/compute/bmc/datastructure.md#marketinginfo)   | Information on marketing campaigns.                                                                                                                                                             |
| tags             | No       | [TagAssociation](/api-reference/compute/bmc/datastructure.md#tagassociation) | <p>Bound tags when creating resources.</p><p>Tag keys must be unique.</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>                                                                                                                                        |
| eipIdSet       | Array of String | <p>ID list of elastic IPs.</p><p>The returned ID list does not mean the creation has been completed.uery the status of the elastic IPs. If the status changes from Creating to Available , it means that the elastic IPs have been created successfully.</p> |
| orderNumber    | String          | <p>Number of order.</p><p>This parameter returns when eipChargeType is PREPAID .</p>                                                                                                                                                                         |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**Create a pay-as-you -go elastic IP with the simplest parameters in zone: SEL-A**

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

Request：
{
    "eipChargeType": "POSTPAID",
    "zoneId": "SEL-A"
}

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

{% 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                                 |
| ---------------- | ---------------------------------- | ------------------------------------------- |
| 400              | INVALID\_EIP\_TYPE\_ZONE\_NO\_SELL | Elastic IPs not available for sale in zone. |
| 404              | INVALID\_ZONE\_NOT\_FOUND          | Zone not found.                             |


---

# 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/compute/bmc/elastic-ip/allocateeipaddresses.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.
