> 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/vpc-network/vpc-route/createroute.md).

# CreateRoute

## 1. API Description

This API (CreateRoute) is used to create a route.

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

* The status of the specified next-hop network interface must be one of `AVAILABLE`, `ATTACHING`, `DETACHING`, and `USED`.
* The specified next-hop network interface must be under the specified VPC.
* Two route types are supported: static and policy.
* Routes with exactly the same configuration cannot exist under the same VPC: for policy routes, the **source IP** and the **destination CIDR block** cannot both be the same; for static routes, the destination CIDR blocks cannot be the same.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name       | Required | Type                                                       | Description                                                                                                                                                                                                     |
| -------------------- | -------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| vpcId                | Yes      | String                                                     | <p>ID of the VPC.</p><p>It can be obtained by calling <a href="/api-reference/zec/vpc-network/describevpcs.md">DescribeVpcs</a>.</p>                                                                            |
| ipVersion            | Yes      | [IpType](/api-reference/zec/datastructure.md#iptype)       | <p>IP stack type.</p><p>The optional values are as follows:</p><p>IPv4 , IPv6</p>                                                                                                                               |
| routeType            | Yes      | [RouteType](/api-reference/zec/datastructure.md#routetype) | Route type.                                                                                                                                                                                                     |
| priority             | Yes      | Integer                                                    | <p>Priority.</p><p>The optional values are integers range from 1 to 65534 .</p><p>Value range: \[1, 65534]</p>                                                                                                  |
| name                 | Yes      | String                                                     | <p>Route name.</p><p>The length is 2 to 63 characters. Only letters, digits, hyphens (-), underscores (\_), slashes (/), and periods (.) are supported, and it must start and end with a letter or a digit.</p> |
| sourceCidrBlock      | No       | String                                                     | <p>Source IP address CIDR block.</p><p>It must be specified when the route type is <code>RouteTypePolicy</code> (policy route).</p>                                                                             |
| destinationCidrBlock | No       | String                                                     | <p>Destination CIDR block for IPv4 or IPv6.</p><p>For example: 10.0.1.0/24 .</p>                                                                                                                                |
| cidrBlock            | No       | String                                                     | <p>CIDR block destination address.</p><p>This field is deprecated. Please use destinationCidrBlock instead.</p>                                                                                                 |
| nextHopId            | No       | String                                                     | <p>Next-hop resource ID.</p><p>Currently, only network interface IDs are supported.</p>                                                                                                                         |
| nextHotId            | No       | String                                                     | <p>ID of the next hop resource.</p><p>Only network interface IDs are supported for now.</p><p>Deprecated. Please use <code>nextHopId</code> instead.</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> |
| routeId        | String | Route ID.                                                                                                             |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**Create an IPv4 static route.**

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

Request:
{
  "vpcId": "<vpcId>",
  "ipVersion": "IPv4",
  "routeType": "RouteTypeStatic",
  "destinationCidrBlock": "10.0.0.0/8",
  "priority": 2,
  "nextHopId": "<nicId>",
  "name": "Test"
}

Response:
{
  "requestId": "TBFC01FCF-6439-4530-ADBC-16809F0C3E8F",
  "response": {
    "requestId": "TBFC01FCF-6439-4530-ADBC-16809F0C3E8F",
    "routeId": "<routeId>"
  }
}
```

{% 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                                            |
| ---------------- | ----------------------------------------- | ------------------------------------------------------ |
| 404              | INVALID\_NIC\_NOT\_FOUND                  | vNIC does not exist.                                   |
| 400              | INVALID\_NIC\_STATUS                      | Current vNIC state does not allow this operation.      |
| 409              | INVALID\_NIC\_ZBG\_REGION\_MISMATCH       | Regions of vNIC and border gateway should be the same. |
| 404              | INVALID\_REGION\_NOT\_FOUND               | The specified region does not exist.                   |
| 404              | INVALID\_VPC\_NOT\_FOUND                  | The global VPC does not exist.                         |
| 404              | INVALID\_ZBG\_NOT\_FOUND                  | Border gateway does not exist.                         |
| 400              | OPERATION\_DENIED\_SUBNET\_CIDR\_CONFLICT | Subnet CIDR ranges conflict.                           |
| 400              | OPERATION\_DENIED\_VPC\_NOT\_EXIST\_NIC   | vNIC does not exist in the VPC.                        |
| 400              | INVALID\_PARAMETER\_CIDR\_ILLEGAL         | Invalid CIDR block.                                    |
