> ## Documentation Index
> Fetch the complete documentation index at: https://docs.autodl.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 弹性部署API文档

> [!NOTE]
>
> 新增接口: [设置调度黑名单](https://docs.autodl.com/api/esd_api_doc.md#设置调度黑名单) 和 [获取地区GPU库存](https://docs.autodl.com/api/esd_api_doc.md#获取弹性部署gpu库存)

使用弹性部署API需先认证企业。了解弹性部署请参考[文档](https://docs.autodl.com/elastic_deployment/elastic_deploy.md)

API服务端HOST地址为：`https://api.autodl.com`

## 鉴权

token获取位置： 「控制台」->「设置」-> 「账号」->[「开发者Token」](https://www.autodl.com/console/center/settings/token)

```
headers = {"Authorization": "token"}
```

## 获取镜像

> [!NOTE]
>
> 镜像为在AutoDL中创建并保存的自定义镜像，创建和保存可通过autodl.com网页完成。暂不支持从外部导入镜像。使用平台提供的基础公共镜像请看文末附录

### 请求

POST `/api/v1/dev/image/private/list`

Body中放置请求参数，参数详情如下：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| page\_index | Int | 是 | 页码 |
| page\_size | Int | 是 | 每页条目数 |
| offset | Int | 否 | 查询的起始偏移量 |

样例：

```
{
    "page_index": 1,
    "page_size": 10,
}
```

### 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data -> list | List\<Response对象> | |

Response对象参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| id | Int | 镜像ID |
| image\_name | String | 镜像名称 |
| image\_uuid | String | 镜像的UUID |

样例：

```
{
    "code": "Success",
    "msg": ""
    "data": {
        "list": [
            {
                "id": 111,
                "image_uuid": "image-db8346e037",
                "image_name": "image name",
            }
        ],
        "page_index": 1,
        "page_size": 10,
        "max_page": 1,
        "offset": 0,
    },
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token",
>     "Content-Type": "application/json"
> }
> url = "https://api.autodl.com/api/v1/dev/image/private/list"
> body = {
>     "page_index": 1,
>     "page_size": 10,
> }
> response = requests.post(url, json=body, headers=headers)
> print(response.content.decode())
> ```

## 创建部署

### 请求

POST `/api/v1/dev/deployment`

Body中放置请求参数，参数详情如下：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| name | String | 是 | 部署名称 |
| deployment\_type | String | 是 | 部署类型。支持ReplicaSet、Job、Container |
| replica\_num | Int | ReplicaSet、Job必填 | 创建容器的副本数量，ReplicaSet、Job必填 |
| parallelism\_num | Int | Job必填 | Job类型部署同时在运行的容器容量 |
| reuse\_container | Bool | 否 | 是否复用已经停止的容器，可显著提升创建容器的速度 |
| reuse\_container\_scope | String | 否 | 可填写：all/deployment，默认为all。控制复用容器范围，设置为all时可复用账号内的所有部署的容器，设置为deployment时只在当前部署内复用容器 |
| service\_port\_protocol | String | 否 | 废弃(请使用service\_6006\_port\_protocol和service\_6008\_port\_protocol) |
| container\_template | Container Template对象 | 是 | |

Container Template对象：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| region\_sign | String | 是 | 废弃。请使用下面的dc\_list字段 |
| dc\_list | list\<String> | 是 | 容器可调度的地区（data\_center），可设置多个地区。地区参数值参考文档最下方附录 |
| service\_6006\_port\_protocol | String | 否 | 设置6006端口映射协议。可取值http/tcp，默认http |
| service\_6008\_port\_protocol | String | 否 | 设置6008端口映射协议。可取值http/tcp，默认http |
| cuda\_v | Int | 否 | 废弃。使用下方的cuda\_v\_from和cuda\_v\_to字段 |
| cuda\_v\_from | Int | 是 | 可调度的机器GPU驱动可支持的CUDA版本范围，约定比如整数112代表11.2的cuda版本，详细规则可以见文末附录CUDA版本 |
| cuda\_v\_to | Int | 是 | 同上 |
| gpu\_name\_set | List\<String> | 是 | 可调度的GPU型号。参考网页创建弹性部署时显示的GPU型号名称 |
| gpu\_num | Int | 是 | 创建容器所需GPU数量 |
| memory\_size\_from | Int | 是 | 可调度的容器内存大小范围。单位：GB |
| memory\_size\_to | Int | 是 | 含义同上 |
| cpu\_num\_from | Int | 是 | 可调度的CPU核心数量范围。单位：1vCPU |
| cpu\_num\_to | Int | 是 | 含义同上 |
| price\_from | Int | 是 | 可调度的价格范围。单位：元 \* 1000，如0.1元填写100 |
| price\_to | Int | 是 | 含义同上 |
| image\_uuid | String | 是 | 私有镜像UUID或平台公共基础镜像的UUID(参考文末附录) |
| cmd\_before\_shutdown | String | 否 | 在停止容器前先执行您设置的此命令，注意该命令执行超时时间为5秒，超时将直接停止容器 |
| cmd | String | 是 | 启动容器命令 |

样例：

```
{
    "name": "api自动创建", 
    "deployment_type": "ReplicaSet", 
    "replica_num": 2, 
    "reuse_container": true,
    "container_template": {
        "dc_list": ["westDC2", "westDC3"], 
        "gpu_name_set": [
            "RTX 4090"
        ], 
        "cuda_v_from": 113,
        "cuda_v_to": 128,
        "gpu_num": 1, 
        "cpu_num_from": 1, 
        "cpu_num_to": 100, 
        "memory_size_from": 1,
        "memory_size_to": 256, 
        "cmd": "sleep 100",
        "price_from": 100,  # 基准价格：0.1元/小时
        "price_to": 9000, # 基准价格：9元/小时
        "image_uuid": "image-db8346e037"
    }
}
```

### 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data | Response对象 | |

Response对象参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| deployment\_uuid | String | 部署的UUID |

样例：

```
{
    "code": "Success",
    "msg": "",
    "data": {
        "deployment_uuid": "833f1cd5a764fa3"
    }
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token",
>     "Content-Type": "application/json"
> }
> url = "https://api.autodl.com/api/v1/dev/deployment"
>
> # 创建ReplicaSet类型部署
> body = {
>     "name": "api自动创建",
>     "deployment_type": "ReplicaSet",
>     "replica_num": 2,
>     "reuse_container": True,
>     "container_template": {
>         "dc_list": ["westDC2", "westDC3"],
>         "gpu_name_set": ["RTX 4090"],
>         "gpu_num": 1,
>         "cuda_v_from": 113,
>         "cuda_v_to": 128,
>         "cpu_num_from": 1,
>         "cpu_num_to": 100,
>         "memory_size_from": 1,
>         "memory_size_to": 256,
>         "cmd": "sleep 100",
>         "price_from": 10,
>         "price_to": 9000,
>         "image_uuid": "image-db8346e037",
>     },
> }
> response = requests.post(url, json=body, headers=headers)
> print(response.content.decode())
>
> # 附：
> # 如果创建Job类型部署，Body为：
> {
>     "name": "api自动创建",
>     "deployment_type": "Job",
>     "replica_num": 4,
>     "parallelism_num": 1,
>     "reuse_container": True,
>     "container_template": {
>         "dc_list": ["westDC2", "westDC3"],
>         "gpu_name_set": ["RTX 4090"],
>         "gpu_num": 1,
>         "cuda_v_from": 113,
>         "cuda_v_to": 128,
>         "cpu_num_from": 1,
>         "cpu_num_to": 100,
>         "memory_size_from": 1,
>         "memory_size_to": 256,
>         "cmd": "sleep 10",
>         "price_from": 10,
>         "price_to": 9000,
>         "image_uuid": "image-db8346e037",
>     },
> }
>
> # 如果创建Container类型部署，Body为：
> {
>     "name": "api自动创建",
>     "deployment_type": "Container",
>     "reuse_container": True,
>     "container_template": {
>         "dc_list": ["westDC2", "westDC3"],
>         "gpu_name_set": ["RTX 4090"],
>         "gpu_num": 1,
>         "cuda_v": 113,
>         "cpu_num_from": 1,
>         "cpu_num_to": 100,
>         "memory_size_from": 1,
>         "memory_size_to": 256,
>         "cmd": "sleep 100",
>         "price_from": 10,
>         "price_to": 9000,
>         "image_uuid": "image-db8346e037",
>     },
> }
> ```

## 获取部署列表

POST `/api/v1/dev/deployment/list`

Body中放置请求参数，参数详情如下：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| page\_index | Int | 是 | 页码 |
| page\_size | Int | 是 | 每页条目数 |
| name | String | 否 | 根据name筛选，不支持模糊查询。name为创建部署时设置的部署名称 |
| status | String | 否 | 根据部署的状态筛选。如果为空则筛选全部记录，传`running`为筛选部署中的记录，传`stopped`为筛选已停止的记录 |
| deployment\_uuid | String | 否 | 选填，可根据部署的UUID筛选 |

样例：

```
{
    "page_index": 1,
    "page_size": 10,
}
```

### 响应

字段含义同创建部署的传参字段含义

样例：

```
{
    "code": "Success",
    "data": {
        "list": [
            {
                "id": 214,
                "uid": 58,
                "uuid": "53a677bb3e281b8",
                "name": "xxxx",
                "deployment_type": "Container",
                "status": "stopped",
                "replica_num": 1,
                "parallelism_num": 1,
                "reuse_container": true,
                "service_port_protocol": "http",
                "starting_num": 0,
                "running_num": 0,
                "finished_num": 2,
                "image_uuid": "image-db8346e037",
                "template": {
                    "region_sign": "",
                    "dc_list": [
                        "westDC2",
                        "westDC3"
                    ],
                    "gpu_name_set": [
                        "Tesla V100-SXM2-32GB"
                    ],
                    "gpu_num": 1,
                    "image_uuid": "image-db8346e037",
                    "image_name": "xxxx",
                    "cmd": "sleep 100",
                    "memory_size_from": 1073741824,
                    "memory_size_to": 274877906944,
                    "cpu_num_from": 1,
                    "cpu_num_to": 100,
                    "price_from": 10,
                    "price_to": 9000,
                    "cuda_v_from": 113,
                    "cuda_v_to": 128,
                },
                "price_estimates": 0,
                "created_at": "2023-01-05T20:34:07+08:00",
                "updated_at": "2023-01-05T20:34:07+08:00",
                "stopped_at": null
            }
        ],
        "page_index": 1,
        "page_size": 10,
        "offset": 0,
        "max_page": 1,
        "result_total": 3,
        "page": 1
    },
    "msg": ""
}
```

## 查询容器事件

可以通过对请求中的offset参数进行设置，轮询该接口获取最新的容器事件

### 请求

POST `/api/v1/dev/deployment/container/event/list`

Body中放置请求参数，参数详情如下：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| deployment\_uuid | String | 是 | 部署的UUID |
| deployment\_container\_uuid | String | 否 | 容器的UUID，可选 |
| page\_index | Int | 是 | 页码 |
| page\_size | Int | 是 | 每页条目数 |
| offset | Int | 否 | 查询的起始偏移量 |

样例：

```
{
    "deployment_uuid": "da497aea1eb8343", 
    "deployment_container_uuid": "", 
    "page_index": 1, 
    "page_size": 10,
    "offset": 0
}
```

### 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data -> list | list\<Response对象> | |

Response对象参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| deployment\_container\_uuid | String | 容器的UUID |
| status | String | 容器的状态类型 |
| created\_at | String | 状态发生时间 |

样例：

```
{
    "code": "Success",
    "data": {
        "list": [
            {
                "deployment_container_uuid": "da497aea1eb8343-f94411a60c-1502e6e2",
                "status": "shutdown",
                "created_at": "2022-12-13T16:42:45+08:00"
            },
            {
                "deployment_container_uuid": "da497aea1eb8343-f94411a60c-1502e6e2",
                "status": "shutting_down",
                "created_at": "2022-12-13T16:42:40+08:00"
            },
            {
                "deployment_container_uuid": "da497aea1eb8343-f94411a60c-1502e6e2",
                "status": "running",
                "created_at": "2022-12-13T16:34:57+08:00"
            },
            {
                "deployment_container_uuid": "da497aea1eb8343-f94411a60c-1502e6e2",
                "status": "oss_merged",
                "created_at": "2022-12-13T16:34:55+08:00"
            },
            {
                "deployment_container_uuid": "da497aea1eb8343-f94411a60c-1502e6e2",
                "status": "starting",
                "created_at": "2022-12-13T16:34:55+08:00"
            },
            {
                "deployment_container_uuid": "da497aea1eb8343-f94411a60c-1502e6e2",
                "status": "created",
                "created_at": "2022-12-13T16:34:54+08:00"
            },
            {
                "deployment_container_uuid": "da497aea1eb8343-f94411a60c-1502e6e2",
                "status": "creating",
                "created_at": "2022-12-13T16:34:47+08:00"
            }
        ],
        "page_index": 1,
        "page_size": 10,
        "offset": 0,
        "max_page": 1,
    },
    "msg": ""
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token",
>     "Content-Type": "application/json"
> }
> url = "https://api.autodl.com/api/v1/dev/deployment/container/event/list"
> body = {
>     "deployment_uuid": "424446e02893b5f",
>     "deployment_container_uuid": "",
>     "page_index": 0,
>     "page_size": 10,
> }
> response = requests.post(url, json=body, headers=headers)
> print(response.content.decode())
> ```

## 查询容器

如果您需要在容器内部获取到容器的UUID，可以通过环境变量`AutoDLContainerUUID`的值获取。

### 请求

POST `/api/v1/dev/deployment/container/list`

Body中放置请求参数，参数详情如下：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| deployment\_uuid | String | 是 | 部署UUID |
| container\_uuid | String | 否 | 筛选container uuid |
| date\_from | String | 否 | 筛选容器创建时间范围 |
| date\_to | String | 否 | 筛选容器创建时间范围 |
| gpu\_name | String | 否 | 筛选GPU型号 |
| cpu\_num\_from | Int | 否 | 筛选容器CPU核心数量范围 |
| cpu\_num\_to | Int | 否 | 筛选容器CPU核心数量范围 |
| memory\_size\_from | Int | 否 | 筛选容器内存大小范围 |
| memory\_size\_to | Int | 否 | 筛选容器内存大小范围 |
| price\_from | Float | 否 | 筛选容器基准价范围 |
| price\_to | Float | 否 | 筛选容器基准价范围 |
| released | bool | 否 | 是否查询已经释放的实例 |
| status | List\<String> | 否 | 筛选指定状态的容器，可设置多个不同状态筛选 |
| page\_index | Int | 是 | 缺省值0 |
| page\_size | Int | 是 | 缺省值10 |
| offset | Int | 否 | 查询的起始偏移量 |

样例：

```
{
    "deployment_uuid": "da497aea1eb8343", 
    "page_index": 1, 
    "page_size": 10
}
```

### 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data -> list | list\<Response对象> | |

Response对象参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| uuid | String | 容器的UUID |
| version | String | 容器的版本，用于区分不同镜像等创建的容器，在更新部署时系统会自动生成或由您自己填写 |
| data\_center | String | 数据中心（地区） |
| deployment\_uuid | String | 部署的UUID |
| machine\_id | String | 主机UUID |
| status | String | 容器的状态 |
| gpu\_name | String | GPU型号 |
| gpu\_num | Int | GPU数量 |
| cpu\_num | Int | CPU数量 |
| memory\_size | Int | 内存大小，单位byte |
| image\_uuid | String | 镜像UUID |
| price | Float | 基准价格，单位：元\*1000 |
| info | Info对象 | |
| started\_at | String | 开始运行时间 |
| stopped\_at | String | 停止时间 |
| created\_at | String | 创建时间 |
| updated\_at | String | 更新时间 |

Info对象：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| ssh\_command | String | SSH登录指令 |
| root\_password | String | SSH密码 |
| service\_6006\_port\_url | String | 映射容器6006端口到公网的服务地址 |
| service\_6008\_port\_url | String | 映射容器6008端口到公网的服务地址 |
| service\_url | String | （废弃，请使用service\_6006\_port\_url和service\_6008\_port\_url） |
| proxy\_host | String | （废弃，请使用service\_6006\_port\_url和service\_6008\_port\_url） |
| custom\_port | Int | （废弃，请使用service\_6006\_port\_url和service\_6008\_port\_url） |

样例：

```
{
    "code": "Success", 
    "msg": "",
    "data": {
        "list": [
            {
                "id": 195, 
                "uuid": "53a677bb3e281b8-f94411a60c-63c24009",
                "data_center": "westDC2",
                "machine_id": "f94411a60c", 
                "deployment_uuid": "da497aea1eb8343", 
                "status": "running", 
                "gpu_name": "TITAN Xp", 
                "gpu_num": 1, 
                "cpu_num": 4, 
                "memory_size": 2147483648, 
                "image_uuid": "image-db8346e037", 
                "price": 1881, 
                "info": {
                    "ssh_command": "ssh -p 21305 root@region-1.autodl.com",
                    "root_password": "xxxxxxxxxx",
                    "service_6006_port_url": "https://region-1.autodl.com:21294",
                    "service_6008_port_url": "region-1.autodl.com:21295",
                }, 
                "started_at": "2022-12-13T16:43:03+08:00", 
                "stopped_at": null, 
                "created_at": "2022-12-13T16:42:50+08:00", 
                "updated_at": "2022-12-13T16:43:03+08:00"
            }
        ], 
        "page_index": 1, 
        "page_size": 10, 
        "max_page": 1, 
    }, 
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token",
>     "Content-Type": "application/json"
> }
> url = "https://api.autodl.com/api/v1/dev/deployment/container/list"
> body = {
>     "deployment_uuid": "424446e02893b5f",
>     "container_uuid": "",
>     "date_from": "",
>     "date_to": "",
>     "gpu_name": "",
>     "cpu_num_from": 0,
>     "cpu_num_to": 0,
>     "memory_size_from": 0,
>     "memory_size_to": 0,
>     "price_from": 0,
>     "price_to": 0,
>     "released": False,
>     "status": ["running"],
>     "page_index": 1,
>     "page_size": 10,
> }
> response = requests.post(url, json=body, headers=headers)
> print(response.content.decode())
> ```

## 停止某容器

除了可以设置副本数量由系统自动伸缩，管理容器生命周期外，该接口支持停止某具体容器。如果您希望停止某容器后不再自动启动新容器维持副本数量，可以通过传入decrease\_one\_replica\_num=true完成，在停止容器的同时将replica num副本数量减少1。注意decrease\_one\_replica\_num参数只对ReplicaSet类型部署有效

### 请求

PUT `/api/v1/dev/deployment/container/stop`

Body中放置请求参数，参数详情如下：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| deployment\_container\_uuid | String | 是 | 部署的容器uuid |
| decrease\_one\_replica\_num | Boolean | 否 | 对于ReplicaSet类型的部署，是否同时将replica num副本数减少1个 |
| no\_cache | Boolean | 否 | 在此容器停止后是否**不**要放入缓存池供复用容器（如果创建部署时没有选择复用容器，那么该字段没有实际作用） 。默认为否，即如果部署有设置复用容器，那么此容器停止后将会在下次被复用 |
| cmd\_before\_shutdown | String | 否 | 在停止容器前先执行您传入的命令，注意该命令执行超时时间为5秒，超时将直接停止容器。如果创建部署时也设置了cmd\_before\_shutdown字段，那么此接口中的值将覆盖部署中的值然后执行(极小概率会出现两者都会执行) |

样例：

```
{
     "deployment_container_uuid": "da497aea1eb8343-f94411a60c-a394fb30",
     "decrease_one_replica_num": false,
     "no_cache": false,
     "cmd_before_shutdown": "sleep 5"
}
```

### 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data | 空 | |

样例：

```
{
    "code": "Success",
    "msg": "",
    "data": null
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token",
>     "Content-Type": "application/json"
> }
> url = "https://api.autodl.com/api/v1/dev/deployment/container/stop"
> body = {
>     "deployment_container_uuid": "da497aea1eb8343-f94411a60c-ec630659",
>     "decrease_one_replica_num": False,
>     "no_cache": False,
>     "cmd_before_shutdown": "sleep 5"
> }
> response = requests.put(url, json=body, headers=headers)
> print(response.content.decode())
> ```

## 设置副本数量

### 请求

PUT `/api/v1/dev/deployment/replica_num`

Body中放置请求参数，参数详情如下：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| deployment\_uuid | String | 是 | 部署uuid |
| replica\_num | Int | 是 | 副本数量。仅支持ReplicaSet的部署类型 |

样例：

```
{
    "deployment_uuid": "xxx",
    "replica_num": 10
}
```

### 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data | 空 | |

样例：

```
{
    "code": "Success",
    "msg": "",
    "data": null
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token",
>     "Content-Type": "application/json"
> }
> url = "https://api.autodl.com/api/v1/dev/deployment/replica_num"
> body = {
>     "deployment_uuid": "5be3045703152b9",
>     "replica_num": 16
> }
> response = requests.put(url, json=body, headers=headers)
> print(response.content.decode())
> ```

## 停止部署

### 请求

PUT `/api/v1/dev/deployment/operate`

Body中放置请求参数，参数详情如下：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| deployment\_uuid | String | 是 | 部署uuid |
| operate | String | 是 | 操作类型。目前只能为："stop" |

样例：

```
{
    "deployment_uuid": "xxx",
    "operate": "stop"
}
```

### 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data | 空 | |

样例：

```
{
    "code": "Success",
    "msg": "",
    "data": null
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token",
>     "Content-Type": "application/json"
> }
> url = "https://api.autodl.com/api/v1/dev/deployment/operate"
> body = {
>     "deployment_uuid": "5be3045703152b9",
>     "operate": "stop"
> }
> response = requests.put(url, json=body, headers=headers)
> print(response.content.decode())
> ```

## 删除部署

如果部署未停止直接执行删除操作，那么系统将会停止和删除部署

### 请求

DELETE `/api/v1/dev/deployment`

Body中放置请求参数，参数详情如下：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| deployment\_uuid | String | 是 | 部署uuid |

样例：

```
{
    "deployment_uuid": "xxx"
}
```

### 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data | 空 | |

样例：

```
{
    "code": "Success",
    "msg": "",
    "data": null
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token",
>     "Content-Type": "application/json"
> }
> url = "https://api.autodl.com/api/v1/dev/deployment"
> body = {
>     "deployment_uuid": "5be3045703152b9"
> }
> response = requests.delete(url, json=body, headers=headers)
> print(response.content.decode())
> ```

## 设置调度黑名单

如果在调度和使用容器的过程中发现某个容器出现未知异常，那么您可以将此容器所在主机设置为禁止调度状态（该禁止状态默认在24小时后自动解除，您也可以设置此时间），设置后在接下来的时间内不会在该主机上调度任何您的部署

### 请求

POST `/api/v1/dev/deployment/blacklist`

Body中放置请求参数，参数详情如下：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| deployment\_container\_uuid | String | 是 | 容器uuid |
| expire\_in\_minutes | Int | 否 | 黑名单过期时间。以分钟为单位，默认为24小时，最长可设置30天 |
| comment | String | 否 | 备注信息 |

样例：

```
{
    "deployment_container_uuid": "xxx",
    "expire_in_minutes": 60,
    "comment": "开机缓慢，禁止在该主机上调度容器"
}
```

### 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data | 空 | |

样例：

```
{
    "code": "Success",
    "msg": "",
    "data": null
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token",
>     "Content-Type": "application/json"
> }
> url = "https://api.autodl.com/api/v1/dev/deployment/blacklist"
> body = {
>     "deployment_container_uuid": "da497aea1eb8343-f94411a60c-1502e6e2",
>     "expire_in_minutes": 60,
>     "comment": "开机缓慢，禁止在该主机上调度容器"
> }
> response = requests.post(url, json=body, headers=headers)
> print(response.content.decode())
> ```

## 获取生效中的调度黑名单

如果您通过API `/api/v1/dev/deployment/blacklist` 设置过调度黑名单，那么可通过此接口查询还在生效中的黑名单列表

### 请求

GET `/api/v1/dev/deployment/blacklist`

Body请求参数无

## 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data | List\<Response>对象 | |

Response对象参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| created\_at | 时间戳 | ”第一次“设置黑名单的时间 |
| updated\_at | 时间戳 | 多次设置黑名单会覆盖到期时间，且更新此时间。即最后更新黑名单的时间 |
| data\_center | String | 地区 |
| expired\_time | 时间戳 | 到期时间 |
| machine\_id | String | 主机ID |
| msg | String | 设置黑名单时传入的备注信息 |

样例：

```
{
    "created_at": "2025-03-25T17:42:55+08:00", 
    "data_center": "westDC2", 
    "expired_time": "2025-03-26T17:48:11+08:00", 
    "machine_id": "24fb4ca36a", 
    "msg": "", 
    "updated_at": "2025-03-25T17:48:11+08:00"
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token",
>     "Content-Type": "application/json"
> }
> url = "https://api.autodl.com/api/v1/dev/deployment/blacklist"
> response = requests.get(url, headers=headers)
> print(response.content.decode())
> ```

## 获取弹性部署GPU库存

### 请求

POST `/api/v1/dev/machine/region/gpu_stock`

Body中放置请求参数，参数详情如下：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| region\_sign | String | 是 | 见附录中的不同地区的标识码 |
| cuda\_v | Int | 否 | 废弃。使用下方的cuda\_v\_from和cuda\_v\_to字段 |
| cuda\_v\_from | Int | 否 | 筛选机器GPU驱动可支持的CUDA版本范围，约定比如整数112代表11.2的cuda版本，详细规则可以见文末附录CUDA版本 |
| cuda\_v\_to | Int | 否 | 含义同上 |
| gpu\_name\_set | List\<String> | 否 | 筛选可调度的GPU型号。参考网页创建弹性部署时显示的GPU型号名称 |
| memory\_size\_from | Int | 否 | 筛选可调度的容器内存大小范围。单位：GB |
| memory\_size\_to | Int | 否 | 含义同上 |
| cpu\_num\_from | Int | 否 | 筛选可调度的CPU核心数量范围。单位：1vCPU |
| cpu\_num\_to | Int | 否 | 含义同上 |
| price\_from | Int | 否 | 筛选可调度的价格范围。单位：元 \* 1000，如0.1元填写100 |
| price\_to | Int | 否 | 含义同上 |

> [!WARNING]
>
> 注意：筛选时，GPU数量默认按调度1张卡的情况进行库存筛选。如果查询库存为2卡，可能在两台不同机器上，如果一个容器需要2卡，那么可能无法调度

样例：

```
{
    "region_sign": "westDC2",
    "cuda_v_from": 117,
    "cuda_v_to": 128
}
```

### 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data -> list | List\<Response对象> | |

Response对象参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| GPU型号 | 库存对象 | |

库存对象参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| idle\_gpu\_num | Int | 空闲数量 |
| total\_gpu\_num | Int | 总数量 |

样例：

```
{
    "code": "Success",
    "msg": "",
    "data": [
        {
            "RTX 4090": {
                "idle_gpu_num": 215,
                "total_gpu_num": 2285
            }
        },
        {
            "RTX 3080 Ti": {
                "idle_gpu_num": 20,
                "total_gpu_num": 392
            }
        },
        {
            "RTX A4000": {
                "idle_gpu_num": 6,
                "total_gpu_num": 24
            }
        }
    ]
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token",
>     "Content-Type": "application/json"
> }
> url = "https://api.autodl.com/api/v1/dev/machine/region/gpu_stock"
> body = {
>     "region_sign": "westDC2",
>     "cuda_v": 117
> }
> response = requests.post(url, json=body, headers=headers)
> print(response.content.decode())
> ```

## 获取已购时长包数据

### 请求

GET `/api/v1/dev/deployment/ddp/overview`

请求参数：

| 参数 | 数据类型 | 是否必须 | 备注 |
| - | - | - | - |
| deployment\_uuid | String | 是 | 部署的uuid |

## 响应

响应参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| code | String | 响应代码，成功时为Success |
| msg | String | 错误信息，成功时为空 |
| data | List对象 | |

Response对象参数：

| 参数 | 数据类型 | 备注 |
| - | - | - |
| gpu\_type | String | GPU型号 |
| total | Int | 还未使用完的时长包总时长，已用完的时长包不做统计，单位：秒 |
| balance | Int | 还未使用完的时长包剩余时长，单位：秒 |
| dc\_list | String | 地区。如果该GPU型号的时长包购买了多个地区，那么会用逗号分隔，比如："westDC2,westDC3" |

样例：

```
{
    "code": "Success",
    "data": [
        {
            "gpu_type": "RTX 4090",
            "total": 86400,
            "balance": 83829,
            "dc_list": "westDC2,westDC3"
        }
    ],
    "msg": ""
}
```

> [tab] Python代码
>
> ```python theme={null}
> import requests
> headers = {
>     "Authorization": "您的token"
> }
> url = "https://api.autodl.com/api/v1/dev/deployment/ddp/overview"
> params = {"deployment_uuid": "your uuid"}
> response = requests.get(url, params=params, headers=headers)
> print(response.content.decode())
> ```

## 附录

**1.** 创建部署时的dc\_list或region\_sign参数值。在容器启动后可通过容器内的`AutoDLDataCenter`环境变量的值对地区进行对应

| 地区 | region\_sign值 |
| - | - |
| 西北企业区(推荐) | westDC2 |
| 西北B区 | westDC3 |
| 北京A区 | beijingDC1 |
| 北京B区 | beijingDC2 |
| L20专区(原北京C区) | beijingDC4 |
| V100专区(原华南A区) | beijingDC3 |
| 内蒙A区 | neimengDC1 |
| 佛山区 | foshanDC1 |
| 重庆A区 | chongqingDC1 |
| 3090专区 | yangzhouDC1 |
| 内蒙B区 | neimengDC3 |

**2.** 公共基础镜像UUID

| 镜像UUID | 框架 | 镜像 |
| - | - | - |
| base-image-12be412037 | PyTorch | cuda11.1-cudnn8-devel-ubuntu18.04-py38-torch1.9.0 |
| base-image-u9r24vthlk | PyTorch | cuda11.3-cudnn8-devel-ubuntu20.04-py38-torch1.10.0 |
| base-image-l374uiucui | PyTorch | cuda11.3-cudnn8-devel-ubuntu20.04-py38-torch1.11.0 |
| base-image-l2t43iu6uk | PyTorch | cuda11.8-cudnn8-devel-ubuntu20.04-py38-torch2.0.0 |
| base-image-0gxqmciyth | TensorFlow | cuda11.2-cudnn8-devel-ubuntu18.04-py38-tf2.5.0 |
| base-image-uxeklgirir | TensorFlow | cuda11.2-cudnn8-devel-ubuntu20.04-py38-tf2.9.0 |
| base-image-4bpg0tt88l | TensorFlow | cuda11.4-py38-tf1.15.5 |
| base-image-mbr2n4urrc | Miniconda | cuda11.6-cudnn8-devel-ubuntu20.04-py38 |
| base-image-qkkhitpik5 | Miniconda | cuda10.2-cudnn7-devel-ubuntu18.04-py38 |
| base-image-h041hn36yt | Miniconda | cuda11.1-cudnn8-devel-ubuntu18.04-py38 |
| base-image-7bn8iqhkb5 | Miniconda | cudagl11.3-cudnn8-devel-ubuntu20.04-py38 |
| base-image-k0vep6kyq8 | Miniconda | cuda9.0-cudnn7-devel-ubuntu16.04-py36 |
| base-image-l2843iu23k | TensorRT | cuda11.8-cudnn8-devel-ubuntu20.04-py38-trt8.5.1 |
| base-image-l2t43iu6uk | TensorRT | cuda11.8-cudnn8-devel-ubuntu20.04-py38-torch2.0.0 |
| ... | ... | 更多新上线的镜像请联系客服 |

**3.** CUDA版本的值

| CUDA版本 | cuda\_v\_from和cuda\_v\_to字段传参值（整型） |
| - | - |
| 11.8 | 118 |
| 12.0 | 120 |
| 12.1 | 121 |
| 12.2 | 122 |
| 依次类推 | ... |

说明：如果您的框架使用的CUDA版本=11.5，上述可选值中没有，那么选择兼容您所需CUDA版本中的最低可选版本，也就是11.8。因为高版本驱动可以兼容低版本CUDA，所以可以正常使用，但是如果选择的版本过高将导致可调度的机器范围缩小，影响可用卡的数量。

**4.** 容器内环境变量

| key | value含义 |
| - | - |
| AutoDLContainerUUID | 容器的UUID |
| AutoDLDeploymentUUID | 部署的UUID |
| AutoDLDataCenter | 地区data\_center |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.