> 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/compute/zec/instance/resetinstance.md).

# ResetInstance

## 1. API Description

This API (ResetInstance) is used to reinstall the operating system on an elastic compute instance.

#### Prerequisites

* Query images: call [DescribeImages](/api-reference/compute/zec/image/describeimages.md) to query the operating system image information required for reinstallation.

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

* If the `imageId` parameter is specified, the instance is reinstalled using the specified image; otherwise, it is reinstalled using the image currently in use by the instance.
* Cross-OS-type (`osType`) reinstallation is not supported — for example, reinstalling an instance with OS type `linux` as `windows`.
* The instance's system disk size must be greater than or equal to the size of the image being reinstalled; otherwise the operation will be rejected.
* The system disk will be formatted and reset; please ensure there are no important files on the system disk.
* You must specify either a password or a key pair — exactly one of the two.
* The instance must be powered off before system reinstallation can be performed.
* `Windows` and `Generic` do not support SSH login via a specified `key_id`.
* After reinstallation, the instance enters the `DEPLOYING` state. If the instance's latest status changes to `RUNNING`, the operation succeeded; if it changes to `REINSTALL_FAILED`, the operation failed — please contact the administrator. The instance status can be queried via the [`DescribeInstancesStatus`](/api-reference/compute/zec/instance/describeinstancesstatus.md) API.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name | Required | Type    | Description                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| instanceId     | Yes      | String  | <p>Instance ID(s).</p><p>To obtain the instance ID, you can call DescribeInstances and look for instanceId in the response.</p>                                                                                                                                                                                                                                        |
| password       | No       | String  | <p>Instance password.</p><p>The parameter must be 8-16 characters, including:</p><p>lowercase letters: \[a-z] uppercase letters: \[A-Z] digits: 0-9 special characters: \`\~!@$^\*-\_=+</p>                                                                                                                                                                            |
| keyId          | No       | String  | <p>SSH key pair ID. For example: key-YWD2QFOl .</p><p>Your SSH key pair contains several public keys that can be placed on your server. You can access your instance with the private key. Call DescribeKeyPairs to obtain key pair information.</p><p>You can set either a password or a keyId , but not both; Windows and Generic images support neither option.</p> |
| imageId        | No       | String  | <p>Specify a valid image ID.</p><p>To obtain valid image ID, you can call DescribeImages and look for imageId in the response. You can also reinstall it according to the original image.</p>                                                                                                                                                                          |
| timezone       | No       | String  | If not specified, the instance will be reinstalled using its original time zone.                                                                                                                                                                                                                                                                                       |
| enableAgent    | No       | Boolean | <p>Whether QGA is enabled or not.</p><p>Default value: false</p>                                                                                                                                                                                                                                                                                                       |
| instanceName   | No       | String  | <p>The modified instance name.</p><p>2–63 characters in length.</p><p>Only letters, numbers, hyphens (-), and periods (.) are allowed.</p>                                                                                                                                                                                                                             |
| userData       | No       | String  | Initialization command.                                                                                                                                                                                                                                                                                                                                                |

## 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> |

## 4. Code Example

{% tabs %} {% tab title="Example" %}

**1. Reinstall the OS.**

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

Request：
{
  "instanceId": "<instanceId>",
  "imageId": "ubuntu2022",
  "password": "Example+123",
  "enableAgent": true
}

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

## 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\_IMAGE\_AGENT\_NOT\_SUPPORT      | QGA is not supported for the selected image.                                       |
| 400              | INVALID\_IMAGE\_KEY\_PAIR\_NOT\_SUPPORT  | The image does not support SSH key pairs.                                          |
| 404              | INVALID\_IMAGE\_NOT\_FOUND               | Image not found.                                                                   |
| 400              | INVALID\_IMAGE\_PASSWORD\_NOT\_SUPPORT   | The operating system does not support the specified password.                      |
| 400              | INVALID\_IMAGE\_SIZE\_EXCEED             | Boot disk size should be larger than the image size.                               |
| 400              | INVALID\_IMAGE\_SPEC\_NOT\_SUPPORT       | The minimum specification required by the image exceeds the current instance type. |
| 400              | INVALID\_IMAGE\_STATUS                   | The image's state does not support this operation.                                 |
| 400              | INVALID\_OS\_TYPE\_NOT\_SAME             | Operating system types are inconsistent, operation not allowed.                    |
| 400              | INVALID\_PARAMETER\_USER\_DATA\_EXCEED   | Initialization command exceeds length limit.                                       |
| 404              | INVALID\_INSTANCE\_NOT\_FOUND            | Instance not found.                                                                |
| 404              | INVALID\_KEY\_PAIR\_NOT\_FOUND           | SSH key pair does not exist.                                                       |
| 400              | INVALID\_KEY\_PAIR\_NOT\_SUPPORT         | Unsupported SSH key pair exists.                                                   |
| 400              | INVALID\_LOGIN\_SETTING\_CONFLICT        | You must and can only pass the value of either password or keyId .                 |
| 400              | INVALID\_PASSWORD\_MALFORMED             | Password format error.                                                             |
| 400              | UNSUPPORTED\_OPERATION\_INSTANCE\_STATUS | Operations on instances in current state are not supported.                        |
