> 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/security/ccs/key-pair/importkeypair.md).

# ImportKeyPair

## 1. API Description

This API (ImportKeyPair) is used to The API is used to import an SSH key pair to log in to a `Linux` instance.

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

* <mark style="color:blue;">This request is to import an SSH key pair to be used for later instance login.</mark>
* <mark style="color:blue;">A key pair name and several public SSH keys are required.</mark>
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name | Required | Type   | Description                                                                                                                                                                                            |
| -------------- | -------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| keyName        | Yes      | String | <p>Key pair name.</p><p>Up to 32 characters in length are supported, containing letters, digits and special character -\_</p><p>The names cannot be duplicated.</p><p>For example: my\_key, my-key</p> |
| publicKey      | Yes      | String | <p>Public SSH keys in OpenSSH format.</p><p>Up to 5 public keys are allowed, separated by pressing ENTER key.</p><p>For example: ssh-rsa XXXXXXXXXXXX key</p>                                          |
| keyDescription | No       | String | <p>Description of key pair.</p><p>Up to 255 characters in length are allowed.</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> |
| keyId          | String | Key pair ID.                                                                                                          |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**Import an SSH key pair.**

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

Request:
{
    "KeyName": "my-key",
    "PublicKey": "ssh-rsa XXXXXXXXXXXX== example"
}

Response:
{
  "requestId": "T69E37B61-4E39-4461-A2BB-205F847D1D60",
  "response": {
    "requestId": "T69E37B61-4E39-4461-A2BB-205F847D1D60",
    "keyId": "key-xxxxx"
  }
}
```

{% 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\_KEY\_PAIR\_ALGORITHM       | The key pair encryption algorithm is not supported. |
| 400              | INVALID\_KEY\_PAIR\_EXCEED\_LIMIT   | Quota limit exceeded.                               |
| 400              | INVALID\_KEY\_PAIR\_MALFORMED       | Name format is invalid.                             |
| 409              | INVALID\_KEY\_PAIR\_NAME\_EXIST     | Key pair name duplicated.                           |
| 400              | INVALID\_PUBLIC\_KEY\_EXCEED\_LIMIT | The number of public keys exceeds the limit.        |
