> 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/zec/vnic/createnetworkinterface.md).

# CreateNetworkInterface

## 1. API Description

This API (CreateNetworkInterface) is used to create an elastic vNIC.

{% hint style="info" %}
**Notes**

* This interface is asynchronous. After a successful call, the elastic vNIC is not created immediately. You need to wait until the status of the network interface changes from `PENDING` to `Available`, which indicates that the creation succeeded. If the status changes to `CREATE_FAILED`, the creation failed.
* The committed traffic package size is valid only when the billing cycle is monthly.
* When the EIP bound through `eipIds` is a CIDR block (Block) EIP, `eipBindType` can only be `Passthrough` and must be specified explicitly (it cannot be omitted, because omitting it is equivalent to `FullNat` and is rejected).
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name     | Required | Type                                                                         | Description                                                                                                                                                                                                                                                                                                                                                                           |
| ------------------ | -------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name               | Yes      | String                                                                       | <p>The name of the vNIC.</p><p>The length is 2 to 63 characters. Only letters, numbers, - and periods (.) are supported. The name must start and end with a number or a letter.</p>                                                                                                                                                                                                   |
| subnetId           | Yes      | String                                                                       | <p>ID of the subnet.</p><p>It can be obtained by calling <a href="/api-reference/zec/vpc-network/describesubnets.md">DescribeSubnets</a>.</p>                                                                                                                                                                                                                                         |
| nicStackType       | No       | [SubnetStackType](/api-reference/zec/datastructure.md#subnetstacktype)       | <p>IP stack type of the network interface.</p><p>If it is not specified, it is determined by the subnet stack type: the network interface is IPv4 when the subnet is IPv4, and IPv6 when the subnet is IPv6.</p><p>Specify this parameter explicitly if a dual-stack network interface is required.</p>                                                                               |
| resourceGroupId    | No       | String                                                                       | <p>The resource group ID of the vNIC.</p><p>If you do not specify a resource group, it is placed in the default resource group.</p>                                                                                                                                                                                                                                                   |
| securityGroupId    | No       | String                                                                       | <p>Specify the security group ID.</p><p>A network interface can be associated with only one security group for now.</p><p>If it is not specified, the security group associated with the VPC is used by default.</p><p>It can be obtained by calling <a href="/api-reference/zec/security-group/describesecuritygroups.md">DescribeSecurityGroups</a>.</p>                            |
| internetChargeType | No       | [InternetChargeType](/api-reference/zec/datastructure.md#internetchargetype) | <p>Network billing model.</p><p>See InternetChargeType for available values.</p><p>If the subnet stack type is IPv6 and the type is Public , this value is required.</p>                                                                                                                                                                                                              |
| bandwidth          | No       | Integer                                                                      | <p>Outbound public network bandwidth cap (Mbps). Unit: Mbps.</p><p>The value differs with different instance types.</p><p>Value range: \[1, +)</p>                                                                                                                                                                                                                                    |
| packageSize        | No       | Float                                                                        | <p>Traffic package size of the public IPv6 address.</p><p>Unit: TB.</p><p>The value must be 0 or a multiple of 0.1.</p><p>This parameter is required when the subnet stack type contains IPv6 that is public and the network billing mode is traffic package billing (<code>ByTrafficPackage</code>).</p><p>Value range: \[0.0, +)</p>                                                |
| clusterId          | No       | String                                                                       | <p>ID of the bandwidth cluster specified for the public IPv6 address.</p><p>This parameter is required when the subnet stack type contains IPv6 that is public and the network billing mode is bandwidth cluster billing (<code>BandwidthCluster</code>).</p>                                                                                                                         |
| eipBindType        | No       | [BindType](/api-reference/zec/datastructure.md#bindtype)                     | <p>Binding mode of the public IP.</p><p>Must be specified when a public IP is assigned.</p><p>When binding a block-type (CIDR) EIP, only <code>Passthrough</code> can be used, and it must be explicitly specified (it cannot be omitted — omitting it is equivalent to <code>FullNat</code> and will be rejected).</p><p>Default value: FullNat</p>                                  |
| eipIds             | No       | Array of String                                                              | <p>Assign existing EIPs to the network interfaces.</p><p>The number of IPs must be the same as the number of network interfaces to be created.</p><p>Make sure that the <code>ipStackType</code> of the network interface to be created contains <code>IPv4</code>.</p><p>It can be obtained by calling <a href="/api-reference/zec/elastic-ip/describeeips.md">DescribeEips</a>.</p> |
| marketingOptions   | No       | [MarketingInfo](/api-reference/zec/datastructure.md#marketinginfo)           | Information on marketing campaigns.                                                                                                                                                                                                                                                                                                                                                   |
| tags               | No       | [TagAssociation](/api-reference/zec/datastructure.md#tagassociation)         | <p>Bound tags when creating the vNIC.</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> |
| nicId          | String | vNIC ID.                                                                                                              |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**1. Create an elastic vNIC in a subnet with the IPv4 stack type.**

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

Request：
{
  "name": "Test-NIC",
  "subnetId": "<subnetId>"
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "nicId": "<nicId>"
  }
}
```

**2. Create an elastic vNIC in a subnet with the IPv4\&IPv6 stack type, with a public IPv6 address. The public IPv6 address is billed by bandwidth cluster.**

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

Request：
{
  "name": "Test-NIC",
  "subnetId": "<subnetId>",
  "internetChargeType": "BandwidthCluster",
  "bandwidth": 100,
  "clusterId": "<clusterId>"
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "nicId": "<nicId>"
  }
}
```

**3. Create an elastic vNIC with a POC voucher. If no POC voucher exists in the system, the creation will fail.**

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

Request：
{
  "name": "Test-NIC",
  "subnetId": "<subnetId>",
  "marketingOptions": {
    "usePocVoucher": true
  }
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "nicId": "<nicId>"
  }
}
```

{% 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\_BINDING\_MODE\_UNSUPPORTED                       | EIP Block does not support NAT binding mode.                                                                   |
| 404              | INVALID\_EIP\_NOT\_FOUND                                       | Elastic IP does not exist.                                                                                     |
| 404              | INVALID\_INSTANCE\_NOT\_FOUND                                  | Instance not found.                                                                                            |
| 400              | INVALID\_IP\_BROADCAST\_ADDRESS                                | The IP address cannot be a broadcast address.                                                                  |
| 400              | INVALID\_IP\_FIRST\_ADDRESS                                    | The IP address cannot be a gateway address.                                                                    |
| 400              | INVALID\_IP\_NETWORK\_ADDRESS                                  | The IP address cannot be a network address.                                                                    |
| 400              | INVALID\_IP\_OUT\_OF\_RANGE                                    | Invalid IP address. It does not belong to the CIDR block.                                                      |
| 409              | INVALID\_NIC\_INSTANCE\_REGION\_MISMATCH                       | Instance and vNIC are not in the same zone.                                                                    |
| 400              | INVALID\_NIC\_IPV6\_EXISTS                                     | vNIC already has an IPv6 assigned; operation not allowed.                                                      |
| 400              | INVALID\_PARAMETER\_BANDWIDTH\_ERROR                           | Bandwidth size is below the minimum limit.                                                                     |
| 400              | INVALID\_PARAMETER\_BANDWIDTH\_EXCEED                          | Bandwidth size exceeds the upper limit.                                                                        |
| 400              | INVALID\_PARAMETER\_FLOW\_TRAFFIC\_PACKAGE                     | Data transfer package size is invalid.                                                                         |
| 400              | INVALID\_PARAMETER\_TRAFFIC\_PACKAGE\_EXCEED                   | Data traffic package exceeds the maximum limit.                                                                |
| 400              | INVALID\_REGION\_NOT\_ON\_SALE                                 | Subnet is not available for sale in the specified region.                                                      |
| 404              | INVALID\_SECURITY\_GROUP\_NOT\_FOUND                           | The specified security group does not exist.                                                                   |
| 409              | INVALID\_SUBNET\_IPV4\_INSUFFICIENT                            | Insufficient available IPv4 addresses in the subnet.                                                           |
| 409              | INVALID\_SUBNET\_IPV6\_INSUFFICIENT                            | Insufficient available IPv6 addresses in the subnet.                                                           |
| 404              | INVALID\_SUBNET\_NOT\_FOUND                                    | Subnet does not exist.                                                                                         |
| 409              | INVALID\_SUBNET\_PRIVATE\_IPV4\_IN\_USED                       | Private IPv4 is occupied.                                                                                      |
| 400              | OPERATION\_DENIED\_EIP\_IS\_DEFAULT                            | Default public IP cannot be unbound.                                                                           |
| 400              | OPERATION\_DENIED\_EIP\_IS\_NOT\_UN\_ASSIGN                    | The EIP is already in use (not in the unbound status) and cannot be bound.                                     |
| 400              | OPERATION\_DENIED\_EIP\_NIC\_NOT\_ADAPTER                      | Specified vNIC count does not match the number of elastic IPs to create.                                       |
| 400              | OPERATION\_DENIED\_EIP\_NOT\_ASSIGNED                          | Elastic IP is not bound.                                                                                       |
| 400              | OPERATION\_DENIED\_INSTANCE\_NIC\_NOT\_ADAPTER                 | Specified instance count does not match the number of vNICs to create.                                         |
| 400              | OPERATION\_DENIED\_INSTANCE\_STATUS\_NOT\_SUPPORT              | Current instance state does not allow this operation.                                                          |
| 400              | OPERATION\_DENIED\_INTERNET\_CHARGE\_TYPE\_NOT\_SUPPORT        | IP network billing type is not supported.                                                                      |
| 400              | OPERATION\_DENIED\_STACK\_TYPE\_NOT\_SUPPORT                   | Stack type is not supported.                                                                                   |
| 400              | OPERATION\_DENIED\_SUBNET\_TYPE\_NOT\_SUPPORT\_IPV4            | Subnet type does not support IPv4.                                                                             |
| 409              | INVALID\_NIC\_EIP\_REGION\_MISMATCH                            | The network card and the EIP are not on the same region.                                                       |
| 400              | OPERATION\_DENIED\_FLOW\_PACKAGE\_NOT\_SUPPORTED\_HOUR\_PERIOD | The current product cycle is based on hourly billing and does not support setting a minimum data package size. |
