tencent cloud



最后更新时间:2022-08-26 10:50:34

1. API Description

Domain name for API request: cvm.tencentcloudapi.com.

This API is used to import key pairs.

  • You can use this API to import key pairs to a user account, but the key pairs will not be automatically associated with any instance. You may use AssociasteInstancesKeyPair to associate key pairs with instances.
  • You need to specify the names of the key pairs and the content of the public keys.
  • If you only have private keys, you can convert them to public keys with the SSL tool before importing them.

A maximum of 10 requests can be initiated per second for this API.

We recommend you to use API Explorer
Try it
API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

2. Input Parameters

The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter Name Required Type Description
Action Yes String Common Params. The value used for this API: ImportKeyPair.
Version Yes String Common Params. The value used for this API: 2017-03-12.
Region Yes String Common Params. For more information, please see the list of regions supported by the product.
KeyName Yes String Key pair name, which can contain numbers, letters, and underscores, with a maximum length of 25 characters.
ProjectId Yes Integer The project ID to which the key pair belongs after it is created.

You can obtain the project ID in the following ways:
  • Check the project list in the Project management page.
  • Call the DescribeProject API and view the projectId in the response.

    If you want to use the default project, specify 0 for the parameter.
  • PublicKey Yes String Content of the public key in the key pair in the OpenSSH RSA format.
    TagSpecification.N No Array of TagSpecification Tag description list. This parameter is used to bind a tag to a key pair.

    3. Output Parameters

    Parameter Name Type Description
    KeyId String Key pair ID
    RequestId String The unique request ID, which is returned for each request. RequestId is required for locating a problem.

    4. Example

    Example1 Importing a key pair

    Input Example

    GET POST / HTTP/1.1
    Host: cvm.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: ImportKeyPair
    <Common request parameters>
        "ProjectId": "0",
        "KeyName": "operation_key",
        "PublicKey": "ssh-rsa XXXXXXXXXXXX== skey_45071"

    Output Example

        "Response": {
            "KeyId": "skey-4e5ty7i8",
            "RequestId": "6EF60BEC-0242-43AF-BB20-270359FB54A7"

    5. Developer Resources


    TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

    Command Line Interface

    6. Error Code

    The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

    Error Code Description
    InternalServerError Internal error.
    InvalidKeyPair.LimitExceeded The number of key pairs exceeds the limit.
    InvalidKeyPairName.Duplicate Key pair name already exists.
    InvalidKeyPairNameEmpty The key name cannot be empty.
    InvalidKeyPairNameIncludeIllegalChar The key name contains invalid characters. Key names can only contain letters, numbers and underscores.
    InvalidKeyPairNameTooLong The key name cannot exceed 25 characters.
    InvalidParameterValue Incorrect parameter value.
    InvalidProjectId.NotFound Invalid project ID: the specified project ID does not exist.
    InvalidPublicKey.Duplicate Invalid public key: the specified key already exists.
    InvalidPublicKey.Malformed Invalid public key: the specified public key does not meet the OpenSSH RSA format requirements.
    LimitExceeded.TagResourceQuota Exceeded the upper limit of resources bound to the tag.
    MissingParameter Missing parameter.




    7x24 电话支持