API
快速开始
从 API 密钥到运行智能体任务并下载结果
前置条件
- 一个处于 Pro 或 Team 套餐、且有预付余额的 BioAgent 账户。API 用量只消耗预付余额,不消耗每日额度。见套餐与计费。
- 一个 API 密钥
下面的步骤假设你的密钥已设置为 BIOAGENT_API_KEY:
export BIOAGENT_API_KEY="<your-api-key>"
要测试 API 密钥,可以尝试列出项目:
curl https://bioagent.cloud/api/v1/projects \
-H "Authorization: Bearer $BIOAGENT_API_KEY"
注意 https://bioagent.cloud/api/v1 是 BioAgent 公开 API 的基础 URL。企业版或私有化部署可能使用不同的基础 URL,请以开通账号时提供给你的地址为准。
使用 BioAgent 智能体
1. 创建项目
开始之前,我们先创建一个项目。项目用于把相关任务与文件归在一起:
PROJECT_ID=$(curl -s -X POST https://bioagent.cloud/api/v1/projects \
-H "Authorization: Bearer $BIOAGENT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"title": "BRCA1 variant workup"}' | jq -r '.id')
返回内容类似:
{
"id": "prj_014OwAG97UY0UfcHlLHQRnKO",
"type": "project",
"title": "BRCA1 variant workup",
"description": "",
"created_at": "2026-08-12T21:21:01.919692Z",
"updated_at": "2026-08-12T21:21:01.919698Z"
}
2. 启动任务
现在有了项目,我们来启动一个任务。任务是与智能体的一次对话:
TASK_ID=$(curl -s -X POST https://bioagent.cloud/api/v1/experimental/tasks \
-H "Authorization: Bearer $BIOAGENT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"project_id": "'"$PROJECT_ID"'",
"title": "BRCA1 variant workup",
"auto_mode": true,
"initial_messages": [
{"role": "user", "content": "Look up the ClinVar status of BRCA1 variants rs80357065, rs28897696, and rs80357382, and write a short markdown summary report."}
]
}' | jq -r '.id')
返回内容类似:
{
"id": "tsk_017ilCeuDpMWTSH9Ah1syUGJ",
"type": "task",
"created_at": "2026-08-12T21:21:02.815306Z",
"status": "running",
"project_id": "prj_014OwAG97UY0UfcHlLHQRnKO",
"title": "BRCA1 variant workup",
"platform": "api"
}
3. 检查状态
智能体开始工作后,我们来检查它。status 会从 running 变为 completed、failed 或 cancelled:
curl -s https://bioagent.cloud/api/v1/experimental/tasks/$TASK_ID \
-H "Authorization: Bearer $BIOAGENT_API_KEY" | jq -r '.status'
完整记录返回内容类似:
{
"id": "tsk_017ilCeuDpMWTSH9Ah1syUGJ",
"type": "task",
"created_at": "2026-08-12T21:21:02.815000Z",
"status": "completed",
"project_id": "prj_014OwAG97UY0UfcHlLHQRnKO",
"title": "BRCA1 variant workup",
"platform": "api",
"reviews": []
}
智能体任务可能运行数小时,因此请为长时间工作做设计,而不是让单个请求阻塞等待结果。
4. 下载结果
任务完成后,我们来收集输出。保存智能体写出的文件:
curl -s "https://bioagent.cloud/api/v1/experimental/tasks/$TASK_ID/results?with_urls=true" \
-H "Authorization: Bearer $BIOAGENT_API_KEY" \
| jq -r '.data[] | .download_url + " -o " + .name' \
| xargs -L1 curl -s
结果列表返回内容类似:
{
"type": "list",
"data": [
{
"type": "result_file",
"result_id": "res_016YNAz7cvmPXcqvGoR1U57t",
"name": "BRCA1_ClinVar_variant_summary.md",
"size_bytes": 6149,
"mime_type": "text/markdown",
"message_id": null,
"created_at": "2026-08-12T21:23:32Z",
"download_url": "https://files.s3.us-west-2.amazonaws.com/...?X-Amz-Signature=..."
}
],
"has_more": false,
"first_id": "res_016YNAz7cvmPXcqvGoR1U57t",
"last_id": "res_016YNAz7cvmPXcqvGoR1U57t"
}
download_url 是预签名且短时有效的,因此列出后请尽快获取。
5. 发送消息
现在有了结果,我们继续对话。在同一个任务中提出后续问题:
curl -s -X POST https://bioagent.cloud/api/v1/experimental/tasks/$TASK_ID/messages \
-H "Authorization: Bearer $BIOAGENT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"content": "Which of those three variants has the strongest PARP inhibitor evidence?"}'
这会返回更新后的任务和你刚发送的消息。回复不在本次响应里:轮询 GET /tasks/{id} 直到
status 离开 running,再从 GET /tasks/{id}/messages 读取。
{
"type": "message_result",
"task": {
"id": "tsk_017ilCeuDpMWTSH9Ah1syUGJ",
"type": "task",
"created_at": "2026-08-12T21:26:51.413000Z",
"status": "running",
"project_id": "prj_014OwAG97UY0UfcHlLHQRnKO",
"title": "BRCA1 variant workup",
"platform": "api"
},
"user_message": {
"id": "msg_f6872d1e0fb242fd",
"type": "message",
"task_id": "tsk_017ilCeuDpMWTSH9Ah1syUGJ",
"created_at": "2026-08-12T21:26:51.413000Z",
"role": "user",
"content": [
{"type": "text", "text": "Which of those three variants has the strongest PARP inhibitor evidence?"}
],
"ai_disclosure": null
},
"assistant_message": null,
"raw": null
}
接下来做什么
恭喜,你刚刚运行了一个 BioAgent 智能体!这个循环是基础,智能体还能做更多事情: