> 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/resetinstances.md).

# ResetInstances

## 1. API Description

This API (ResetInstances) is used to reinstalls the operating system on one or more elastic compute instances. You can specify a new image, login method (password or key pair), time zone, and instance name.

#### 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 instances are reinstalled using the specified image; otherwise, each instance is reinstalled using its current image.
* 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.
* System reinstallation can only be performed while the instance is powered off.
* `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                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | -------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| instanceIds    | Yes      | Array of String | The instance IDs to be reinstalled.                                                                                                                                                                                                                                                                                                                                    |
| password       | No       | String          | <p>The new password for the instance.</p><p>You can set either a password or a keyId, but not both; Windows and Generic images support neither option.</p><p>The password must contain the following three character types: uppercase and lowercase letters: \[a-zA-Z], digits: 0-9, and special characters: \~!@$^\*-\_=+</p>                                         |
| keyId          | No       | String          | <p>SSH key pair ID.</p><p>You can set either a password or a keyId, but not both; Windows and Generic images support neither option.</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>Example: key-YWD2QFOl.</p> |
| imageId        | No       | String          | <p>Specify a valid image ID.</p><p>To obtain valid image ID, you can call <a href="/pages/1vlYMU8pvRGx6IwnzBvO">DescribeImages</a> and look for imageId in the response.</p><p>If not specified, the instance will be reinstalled using the current image.</p>                                                                                                         |
| timezone       | No       | String          | Time zone configuration for the operating system.                                                                                                                                                                                                                                                                                                                      |
| 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> |
| instanceIds    | Array of String | List of instance IDs for which the reinstallation operation failed.                                                   |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**1. Reinstall the OS on multiple instances in a batch.**

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

Request：
{
  "instanceIds": ["<instanceId1>" , "<instanceId2>"],
  "imageId": "ubuntu2022",
  "password": "Example+123",
  "enableAgent": true
}

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

{% 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 |
| ---------------- | ---------- | ----------- |
