> 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/compute/bmc/cidr-block/createipv4block.md).

# CreateIpv4Block

## 1. API Description

This API (CreateIpv4Block) is used to create one or more IPv4 CIDR blocks.

#### Prerequisites

* Query stock: call [`DescribeAvailableIpv4Resources`](/api-reference/compute/bmc/cidr-block/describeavailableipv4resources.md) to check available resources.
* Cost estimation: know of CIDR block pricing. See [Billing Method](https://docs.console.zenlayer.com/welcome/pricing/bare-metal-cloud-pricing/billing-method#cidr-block) for more details.

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

* <mark style="color:blue;">If you create a subscription CIDR block, the amount required will be pre-deducted. If the balance is insufficient, the request will fail. If you create a pay-as-you-go CIDR block, please ensure your account balance is sufficient before calling this API.</mark>
* <mark style="color:blue;">Vouchers can be used for fee deduction in instance creation. See</mark> [<mark style="color:purple;">Vouchers</mark>](https://docs.console.zenlayer.com/welcome/platform/billing-center/vouchers) <mark style="color:blue;">for more details.</mark>
* <mark style="color:blue;">This API is an async API. A CIDR block ID list is returned after the creation request is sent. However, it does not mean the creation has been completed. The status of the CIDR block will be</mark> <mark style="color:blue;">`CREATING`</mark> <mark style="color:blue;">during the creation. You can use</mark> [<mark style="color:blue;">DescribeCidrBlocks</mark>](/api-reference/compute/bmc/cidr-block/describecidrblocks.md) <mark style="color:blue;">to query the status of the CIDR block. 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 CIDR block has been created successfully;</mark> <mark style="color:blue;">`CREATE_FAILED`</mark> <mark style="color:blue;">means the CIDR block has been created failed. Any operations on the instances are not allowed while creating.</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 CIDR blocks belong.                                                                                                                                                                                 |
| chargeType       | Yes      | [ChargeType](/api-reference/compute/bmc/datastructure.md#chargetype)         | <p>CIDR block pricing model .</p><p>PREPAID: subscription POSTPAID: pay-as-you-go</p>                                                                                                                                    |
| netmask          | Yes      | Integer                                                                      | <p>Netmasks you want to purchase.</p><p>Value range: \[1,32].</p><p>You can find the available netmasks in the response by calling DescribeAvailableIpv4Resource .</p><p>Value range: \[1, 32]</p>                       |
| name             | No       | String                                                                       | <p>CIDR block name to be displayed.</p><p>This parameter can contain up to 64 characters.</p>                                                                                                                            |
| cidrType         | No       | [CidrBlockType](/api-reference/compute/bmc/datastructure.md#cidrblocktype)   | <p>CIDR block type.</p><p>Default value: BGP</p>                                                                                                                                                                         |
| chargePrepaid    | 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 chargeType is PREPAID .                                                                                          |
| amount           | No       | Integer                                                                      | <p>Quantity of IPv4 CIDR blocks you want to purchase.</p><p>Default value: 1.</p><p>Value range: \[1, +)</p>                                                                                                             |
| resourceGroupId  | No       | String                                                                       | <p>Resource group ID where the CIDR blocks reside.</p><p>If an available VLAN exists in the specified zone, this parameter will be ignored. The created CIDR blocks will be added to the resource group of the VLAN.</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> |
| orderNumber    | String          | Number of order.                                                                                                      |
| cidrBlockIds   | Array of String | List of CIDR block IDs.                                                                                               |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
Create a postpaid IPv4 CIDR block `example1` with the netmask of `29` in `IST-B`, belonging to `Default Resource Group`.

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

Request:
{
  "zoneId": "IST-B",
  "name": "example1",
  "chargeType": "POSTPAID",
  "netmask": 29
}

Response:
{
  "requestId": "T135376EE-7090-4773-B81E-7FB38358B656",
  "response": {
    "requestId": "T135376EE-7090-4773-B81E-7FB38358B656",
    "orderNumber": "orderNum",
    "cidrBlockIds": [
      "cidrBlockId"
    ]
  }
}
```

{% 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              | OPERATION\_DENIED\_NETMASK\_OUT\_OF\_STOCK | Netmask out of stock. |
| 404              | INVALID\_ZONE\_NOT\_FOUND                  | Zone not found.       |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.console.zenlayer.com/api-reference/compute/bmc/cidr-block/createipv4block.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
