跳转到内容

快速开始

API Key 可通过已认证的 Web 控制台 管理。新创建的 Key 格式如下:

API Key 格式示例
tk_0123456789abcdef0123456789abcdef

该 API Key 可在 Web 控制台中再次查看和复制。

请求任务列表来测试认证是否成功:

验证 API Key
curl https://api.topmaterial-tech.com/api/v2/task/list \
-H "Authorization: Bearer tk_0123456789abcdef0123456789abcdef"

成功后会返回你的任务列表,说明 Key 可正常用于任务接口。

创建任务前,建议先用数据库接口发现可用的数据库:调用 GET /api/v2/database/by-task?task_type=line_calculation 筛选支持目标任务类型的数据库,并将返回的数据库 code 填入 task_config.tdb_code。创建任务会校验你对该数据库的订阅访问权限。

使用 JSON 请求体提交计算任务:

创建计算任务
curl -X POST https://api.topmaterial-tech.com/api/v2/task \
-H "Authorization: Bearer tk_0123456789abcdef0123456789abcdef" \
-H "Content-Type: application/json" \
-d '{
"title": "Line-Calculation-Demo",
"engine": "topthermo_next",
"task_config": {
"task_type": "line_calculation",
"tdb_code": "TOPDB-B-C-Si-Zr-Hf-La-Y-Ti-O.TOPDB",
"task_path": "",
"condition": {
"components": ["HF", "C"],
"compositions_start": { "HF": 0.8, "C": 0.2 },
"compositions_end": { "HF": 0.8, "C": 0.2 },
"temperature_start": 300,
"temperature_end": 3000,
"pressure": 101325,
"points": 101,
"activated_phases": [],
"topthermo_outputs": ["T", "P", "phase_name", "x(*)", "G", "H", "S"]
}
},
"omp_threads": 4,
"no_cache": false
}'

engine 可省略,默认值为 topthermo_next

响应会返回任务 ID 和初始状态:

响应中的 task_type 是服务端存储的具体计算类型,取自 task_config.task_type,因此本例返回 line_calculation

响应示例:任务已创建
{
"id": 42,
"status": "pending",
"task_type": "line_calculation",
"tdb_code": "TOPDB-B-C-Si-Zr-Hf-La-Y-Ti-O.TOPDB"
}

不断查询任务状态直到完成:

轮询任务状态
curl https://api.topmaterial-tech.com/api/v2/task/42 \
-H "Authorization: Bearer tk_0123456789abcdef0123456789abcdef"

当任务状态变为 completed 后,获取结果文件列表:

获取结果文件列表
curl https://api.topmaterial-tech.com/api/v2/task/42/result \
-H "Authorization: Bearer tk_0123456789abcdef0123456789abcdef"