> 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/zec/image/createimage.md).

# CreateImage

## 1. API Description

This API (CreateImage) is used to create a custom image from an instance.

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

* This interface is asynchronous. The request to create an image returns immediately after it is sent successfully, but the operation is not completed at that point. The creation result can be queried by calling the [DescribeCustomImages](/api-reference/zec/image/describecustomimages.md) interface: if the image status changes from `CREATING` to `AVAILABLE`, the creation succeeded; if it changes to `FAILED`, the creation failed. The image cannot be deleted during the creation.
* The corresponding custom image is created in the zone where the instance is located.
* The selected instance must be in the `STOPPED` status.
* GPU instance types do not support creating custom images for now.
* If the quantity exceeds the quota limit, you can contact Support to increase the quota.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name  | Required | Type                                                                 | Description                                                                                                                                                                            |
| --------------- | -------- | -------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| instanceId      | Yes      | String                                                               | <p>ID of the instance from which the image is to be created.</p><p>It can be obtained by calling <a href="/api-reference/zec/instance/describeinstances.md">DescribeInstances</a>.</p> |
| imageName       | Yes      | String                                                               | <p>Image name.</p><p>This parameter must start with a number or a letter, containing 2 to 63 characters. Only letters, numbers, -/\_ and periods (.) are supported.</p>                |
| resourceGroupId | No       | String                                                               | <p>Resource group ID where the image reside.</p><p>If the value is empty, the image will be added into the default resource group.</p>                                                 |
| tags            | No       | [TagAssociation](/api-reference/zec/datastructure.md#tagassociation) | <p>Bound tags when creating the image.</p><p>Tag keys must be unique.</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> |
| imageId        | String | Image ID.                                                                                                             |
| imageName      | String | Image name.                                                                                                           |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**Create a custom image from an instance.**

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

Request：
{
  "instanceId": "<instance id>",
  "imageName": "imageXXX"
}

Response：
{
  "requestId": "TBFC01FCF-6439-4530-ADBC-16809F0C3E8F",
  "response": {
    "requestId": "TBFC01FCF-6439-4530-ADBC-16809F0C3E8F",
    "imageId": "imageIdX",
    "imageName": "imageNameX"
  }
}
```

{% 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\_IMAGE\_QUOTA\_EXCEED                     | Quota limit of custom image is exceeded.                   |
| 404              | INVALID\_INSTANCE\_NOT\_FOUND                     | Instance not found.                                        |
| 400              | OPERATION\_DENIED\_GPU\_INSTANCE\_NOT\_SUPPORT    | GPU instances are not supported for custom image creation. |
| 400              | OPERATION\_DENIED\_INSTANCE\_IN\_OPERATION        | Instance is performing another operation.                  |
| 400              | OPERATION\_DENIED\_INSTANCE\_STATUS\_NOT\_SUPPORT | Current instance state does not allow this operation.      |
