> 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/cn/legacy/vm/virtual-machine-instance/inquirypricecreateinstance.md).

# InquiryPriceCreateInstance

## 1. 接口描述

本接口(InquiryPriceCreateInstance)用于创建一台虚拟机实例询价。

## 2. 请求参数

以下请求参数列表仅列出了接口中需要的请求参数

| 参数名称                    | 必选 | 类型                                                                                    | 描述                                                     |
| ----------------------- | -- | ------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| zoneId                  | 是  | String                                                                                | 实例所属的可用区ID。                                            |
| instanceType            | 是  | String                                                                                | 实例机型。                                                  |
| instanceChargeType      | 是  | [ChargeType](/api-reference/cn/legacy/vm/datastructure.md#chargetype)                 | <p>实例计费类型。</p><p>PREPAID：预付费。</p><p>POSTPAID：后付费。</p>  |
| internetChargeType      | 是  | [InternetChargeType](/api-reference/cn/legacy/vm/datastructure.md#internetchargetype) | 网络计费类型。                                                |
| instanceCount           | 是  | Integer                                                                               | <p>指定创建实例的数量。</p><p>可选值范围：\[1, 100]</p><p>默认值：1</p>    |
| systemDisk              | 是  | [SystemDisk](/api-reference/cn/legacy/vm/datastructure.md#systemdisk)                 | 系统盘配置。                                                 |
| imageId                 | 否  | String                                                                                | 指定有效的镜像ID。                                             |
| instanceChargePrepaid   | 否  | [ChargePrepaid](/api-reference/cn/legacy/vm/datastructure.md#chargeprepaid)           | <p>预付费模式，即包年包月相关参数设置。</p><p>若指定实例的付费模式为预付费则该参数必传。</p>  |
| instanceChargePostpaid  | 否  | [ChargePostpaid](/api-reference/cn/legacy/vm/datastructure.md#chargepostpaid)         | 后付费模式相关参数设置。                                           |
| trafficPackageSize      | 否  | Float                                                                                 | <p>流量包订购大小，单位TB。</p><p>可选值范围：\[0.0, +)</p>             |
| internetMaxBandwidthOut | 否  | Integer                                                                               | <p>公网出带宽上限，单位Mbps。</p><p>可选值范围：\[1, +)</p><p>默认值：1</p> |
| dataDisks               | 否  | Array of [DataDisk](/api-reference/cn/legacy/vm/datastructure.md#datadisk)            | 数据盘配置。                                                 |

## 3. 响应结果

| 参数名称            | 类型                                                                           | 描述                                                       |
| --------------- | ---------------------------------------------------------------------------- | -------------------------------------------------------- |
| requestId       | String                                                                       | <p>唯一请求 ID。</p><p>每次请求都会返回。定位问题时需要提供该次请求的 requestId。</p> |
| instancePrice   | [PriceItem](/api-reference/cn/legacy/vm/datastructure.md#priceitem)          | 实例价格。                                                    |
| bandwidthPrice  | Array of [PriceItem](/api-reference/cn/legacy/vm/datastructure.md#priceitem) | 公网带宽价格。                                                  |
| eipPrice        | [PriceItem](/api-reference/cn/legacy/vm/datastructure.md#priceitem)          | 弹性IP价格。                                                  |
| systemDiskPrice | [PriceItem](/api-reference/cn/legacy/vm/datastructure.md#priceitem)          | 系统盘价格。                                                   |
| dataDiskPrice   | [PriceItem](/api-reference/cn/legacy/vm/datastructure.md#priceitem)          | 数据盘价格。                                                   |
| dataDiskPrices  | Array of [DataDisk](/api-reference/cn/legacy/vm/datastructure.md#datadisk)   | 每种规格数据盘的价格。                                              |

## 4. 代码示例

{% tabs %}
{% tab title="示例" %}
**1. 查询创建预付费实例的询价，带宽计费为固定带宽。**

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

Request:
{
    "zoneId":"SAO-A",
    "instanceType":"c.1c2g",
    "imageId":"img-yKK4q6XybymPgfx7ynUUqC3N8",
    "instanceChargeType":"PREPAID",
    "internetChargeType":"ByBandwidth",
    "instanceChargePrepaid":{
        "period":1
    },
    "internetMaxBandwidthOut":1,
    "systemDisk":{
        "diskSize":10
    }
}

Response:
{
    "requestId":"T03681166-F646-4F6A-AE6E-6CFF08DE60B3",
    "response":{
        "requestId":"T03681166-F646-4F6A-AE6E-6CFF08DE60B3",
        "instancePrice":{
            "discount":95,
            "discountPrice":13.3,
            "originalPrice":14
        },
        "bandwidthPrice":[
            {
                "discount":95,
                "discountPrice":3.8,
                "originalPrice":4
            }
        ],
        "systemDiskPrice":{
            "discount":96,
            "discountPrice":0.48,
            "originalPrice":0.5
        }
    }
}
```

**3. 查询创建预付费实例的询价，带宽计费为流量包。**

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

Request:
{
    "zoneId":"SAO-A",
    "instanceType":"c.1c2g",
    "imageId":"img-yKK4q6XybymPgfx7ynUUqC3N8",
    "instanceChargeType":"PREPAID",
    "internetChargeType":"ByTrafficPackage",
    "trafficPackageSize":10,
    "instanceChargePrepaid":{
        "period":1
    },
    "internetMaxBandwidthOut":1,
    "systemDisk":{
        "diskSize":10
    }
}

Response:
{
    "requestId":"T70B50FA0-A8CB-4DC3-BA38-22E22AA9FB57",
    "response":{
        "requestId":"T70B50FA0-A8CB-4DC3-BA38-22E22AA9FB57",
        "instancePrice":{
            "discount":95,
            "discountPrice":13.3,
            "originalPrice":14
        },
        "bandwidthPrice":[
            {
                "discount":100,
                "discountPrice":0,
                "originalPrice":0
            },
            {
                "discount":100,
                "stepPrices":[
                    {
                        "stepStart":0,
                        "unitPrice":0.5,
                        "discountUnitPrice":0.5
                    }
                ]
            }
        ],
        "systemDiskPrice":{
            "discount":96,
            "discountPrice":0.48,
            "originalPrice":0.5
        }
    }
}
```

{% endtab %}
{% endtabs %}

## 5. 开发者工具

Zenlayer Cloud API 2.0 提供了配套的[开发工具集（SDK）](/api-reference/cn/api-introduction/toolkit.md)，未来会陆续支持更多开发语言，方便快速接入和使用Zenlayer的产品和服务。

## 6. 错误码

下面包含业务逻辑中遇到的错误码，其他错误码见[公共错误码](/api-reference/cn/api-introduction/instruction/commonerrorcode.md)

| HTTP状态码 | 错误码                                          | 说明                        |
| ------- | -------------------------------------------- | ------------------------- |
| 404     | INVALID\_ZONE\_NOT\_FOUND                    | 指定的可用区不存在。                |
| 404     | INVALID\_INSTANCE\_TYPE\_NOT\_FOUND          | 未找到指定的实例规格。               |
| 400     | INVALID\_INSTANCE\_TYPE\_ZONE\_NO\_SELL      | 所选规格在所选区域已售罄或未开售。         |
| 400     | INVALID\_INSTANCE\_BANDWIDTH\_ZONE\_NO\_SELL | 指定的公网计费类型在所选的可用区不支持。      |
| 400     | INVALID\_PARAMETER\_TRAFFIC\_PACKAGE         | 设定的流量包大小值不合法，必须是0.1或1的倍数。 |
| 400     | INVALID\_PARAMETER\_TRAFFIC\_PACKAGE\_EXCEED | 设定的流量包大小超过最大限制。           |
