All Products
Search
Document Center

ENS:DetachKeyPair

Last Updated:Mar 25, 2026

Detaches a key pair from up to 30 instances in a single request. You can specify the key pair by its key pair name or key pair ID.

Operation description

Usage notes

This operation detaches a key pair from multiple instances in a batch. The target instances must be in a stopped state.

  • You can detach a key pair from a maximum of 30 instances in a single request.

  • The operation returns an error if you specify the KeyPairName parameter and any of the specified instances are not associated with that key pair name.

  • You must specify either the KeyPairName or KeyPairId parameter.

  • We recommend using the KeyPairId parameter. The KeyPairName parameter will be deprecated in a future release.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

No authorization for this operation. If you encounter issues with this operation, contact technical support.

Request parameters

Parameter

Type

Required

Description

Example

KeyPairName

string

No

The name of the key pair.

test-kp

KeyPairId

string

No

The ID of the key pair.

ssh-xxx

InstanceIds

array

Yes

An array of instance IDs from which to detach the key pair.

["i-50f8q9mbfjzlkuk9znjglnne3"]

string

No

An instance ID.

i-xxxu

Response elements

Element

Type

Description

Example

object

The response object.

RequestId

string

The request ID.

xx-xx-xx-xx

KeyPairId

string

The ID of the key pair.

ssh-xxx

KeyPairName

string

The name of the key pair.

test-kp

FailCount

integer

The number of instances for which the detach operation failed.

1

TotalCount

integer

The total number of instances specified in the request.

3

Results

array<object>

The results of the operation for each instance.

object

Code

integer

The status code for the operation on a specific instance. A value of 200 indicates a successful operation.

200

InstanceId

string

The instance ID.

i-xxx

Message

string

The response message for the operation. If the Code is 200, the message is successful.

successful

Success

boolean

Indicates whether the operation on the instance succeeded. Valid values: true and false.

true

Examples

Success response

JSON format

{
  "RequestId": "xx-xx-xx-xx",
  "KeyPairId": "ssh-xxx",
  "KeyPairName": "test-kp",
  "FailCount": 1,
  "TotalCount": 3,
  "Results": [
    {
      "Code": 200,
      "InstanceId": "i-xxx",
      "Message": "successful",
      "Success": true
    }
  ]
}

Error codes

HTTP status code

Error code

Error message

Description

400 PublicKeyNotAttachWithInstance Public Key Not Attach With Instance. Public key not bound to instance
400 NoPermission Permission denied.
400 InvalidParameter.%s The specified field %s invalid. Please check it again.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.