# CreateImage

## 1. API Description

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

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>

* <mark style="color:blue;">A custom image will be created in the same availability zone as the selected instance.</mark>
* <mark style="color:blue;">The instance must be in the</mark> <mark style="color:blue;">`STOPPED`</mark> <mark style="color:blue;">state.</mark>
* <mark style="color:blue;">GPU instances are currently not supported for custom image creation.</mark>
* <mark style="color:blue;">If the quota limit is exceeded, please contact us to request an increase.</mark>
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name  | Required | Type                                                                                                   | Description                                                                                                                                                             |
| --------------- | -------- | ------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| instanceId      | Yes      | String                                                                                                 | Instance ID from which you create the image.                                                                                                                            |
| 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](https://docs.console.zenlayer.com/api-reference/compute/datastructure#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](https://docs.console.zenlayer.com/api-reference/api-introduction/toolkit/api-sdk)，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](https://docs.console.zenlayer.com/api-reference/api-introduction/instruction/commonerrorcode).

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