🚀 快速开始
PRIME API 让您在自己的应用中调用平台的文献问答、综述生成、引用核查等能力。所有接口均为 HTTPS,返回 JSON 格式(流式接口除外)。
✅
Base URL:
https://traumadatacenter.com · 所有路径以 /ai/api/ 开头
⚠️
尚未拥有 API Key?请先 提交申请 →,审核通过后通过邮件发放(1–3 工作日)。
最简示例
发送一次文献问答请求:
# 使用 curl
curl -X POST https://traumadatacenter.com/ai/api/ask \
-H "Content-Type: application/json" \
-H "X-API-Key: PRIME_你的密钥" \
-d '{"question": "ARDS机械通气的最新进展"}'
🔐 认证方式
每个请求都需要在 HTTP Header 中携带 API Key,支持两种方式(任选其一):
方式一:X-API-Key(推荐)
X-API-Key: PRIME_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
方式二:Authorization Bearer
Authorization: Bearer PRIME_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
⚠️
API Key 请妥善保管,不要暴露在前端代码或公开仓库中。如发生泄露请联系管理员重新签发。
⚠️ 错误码
所有错误返回 JSON:
{"error": "错误描述", "code": "错误代码"}🪙 Token 计量
系统精确记录每次 API 调用实际消耗的 LLM tokens(Prompt tokens + Completion tokens),与 DeepSeek API 计量口径完全一致。不同接口因任务复杂度不同,实际消耗差异较大,典型参考值如下:
💡 可通过 Token 用量监控页面 或
GET /ai/api/my_usage 接口查看您的实际消耗明细与趋势图。
📚 文献问答
基于 PubMed 实时检索,对医学问题给出带引用的综合答案。适合单次同步调用(等待完整响应)。
POST
/ai/api/ask
模块:ask_agent · 按实际 LLM tokens 计量
请求参数(JSON Body)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| question | string | 必填 | 问题内容,支持中英文 |
| date_from | string | 可选 | 检索文献起始年份,如 "2020" |
| date_to | string | 可选 | 检索文献截止年份,如 "2024" |
| max_refs | integer | 可选 | 最多参考文献数(默认 10,最大 30) |
| category_id | string | 可选 | 限定文献分类 ID |
| file_content | string | 可选 | 附件文本内容(PDF/TXT 提取后的纯文本) |
请求示例
{
"question": "机械通气在ARDS中的保护性策略有哪些循证依据?",
"date_from": "2018",
"max_refs": 10
}
返回示例
{
"answer": "根据现有循证医学证据,ARDS的机械通气保护策略主要包括...[1][2][3]",
"references": [
{
"pmid": "12345678",
"title": "Low tidal volume ventilation in ARDS...",
"authors": "Smith J, et al.",
"journal": "N Engl J Med",
"year": "2020"
}
]
}
⚡ 流式问答
与
/ask 功能相同,但以 Server-Sent Events(SSE)格式实时推送,适合在界面上逐字展示结果。
POST
/ai/api/ask_stream
模块:ask_agent · 按实际 LLM tokens 计量
请求参数(JSON Body)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| question | string | 必填 | 问题内容 |
| lang | string | 可选 | "zh" 或 "en",强制输出语言 |
| history | array | 可选 | 对话历史,格式 [{"q":"...","a":"..."}],最多取最近 6 轮 |
| file_content | string | 可选 | 附件文本内容 |
| images | array | 可选 | 图片 Base64 数组,用于视觉分析 |
SSE 事件类型
thinkingAI 正在思考,data 含
message 字段(推理过程说明)tool_call正在调用工具(如检索 PubMed),data 含
tool 和 inputtool_result工具调用结果,data 含检索到的文献摘要等
answer_chunk答案文字片段,data 含
text 字段,拼接即为完整答案references答案引用的文献列表,data 含
refs 数组done流结束
error发生错误,data 含
message 字段📝 综述生成
围绕主题自动检索 PubMed 文献,生成结构化学术综述。消耗 Token 较多,建议提供明确的主题和时间范围。
POST
/ai/api/expert
模块:expert_agent · 按实际 LLM tokens 计量
请求参数(JSON Body)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| question | string | 必填 | 综述主题,越明确效果越好 |
| date_from | string | 可选 | 文献检索起始年份 |
| date_to | string | 可选 | 文献检索截止年份 |
| max_refs | integer | 可选 | 最多参考文献数 |
ℹ️
也支持
POST /ai/api/expert_stream 流式版本,SSE 事件格式同 /ask_stream。
🔍 引用核查
检验综述句子中的数据是否与原始 PubMed 文献摘要一致,识别数字偏差、上下文错位、过度引申等问题。
POST
/ai/api/factcheck_verify
模块:factcheck · 按实际 LLM tokens 计量
请求参数(JSON Body)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| sentence | string | 必填 | 待核查的综述句子 |
| pmid | string | 必填 | 引用文献的 PubMed ID |
| abstract | string | 可选 | 已知摘要内容(提供可减少网络请求延迟) |
请求示例
{
"sentence": "该研究显示低潮气量通气将死亡率降低了15%",
"pmid": "10793162"
}
返回示例
{
"consistent": false,
"is_review_citation": false,
"reason": "摘要显示死亡率降低了8.8个百分点(39.8% vs 31.0%),非15%",
"deviation_analysis": "数字偏差:综述将相对变化误写为绝对数值",
"suggestion": "建议修改为:该研究显示低潮气量通气将绝对死亡率降低8.8个百分点",
"pmid": "10793162",
"abstract": "..."
}
✍️ 文本润色
对医学学术文本进行语言润色,保持原意不变,改善流畅性和规范性,支持流式返回。
POST
/ai/api/polish
模块:ask_agent · 按实际 LLM tokens 计量
请求参数(JSON Body)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| text | string | 必填 | 待润色文本(最多 20,000 字符) |
| requirement | string | 可选 | 润色要求,默认 "学术润色,改善语言表达" |
| insert_refs | boolean | 可选 | 是否自动补充引用文献,默认 true |
ℹ️
该接口以 SSE 流式格式返回,事件类型参考 SSE 流式协议。
🔎 高级检索
在平台本地文献数据库中执行多条件检索,返回匹配文献列表,无需 AI 推理,响应速度快。
POST
/ai/api/local_advanced_search
模块:ask_agent · 按实际 LLM tokens 计量
请求参数(JSON Body)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| terms | array | 可选 | 检索条件数组,每项含 field(如 title/abstract/keyword)和 value |
| year_from | string | 可选 | 发表年份下限 |
| year_to | string | 可选 | 发表年份上限 |
| sort | string | 可选 | "date_desc"(默认)或 "relevance" |
| limit | integer | 可选 | 返回条数,默认 50,最大 100 |
| offset | integer | 可选 | 分页偏移量,默认 0 |
请求示例
{
"terms": [
{"field": "keyword", "value": "ARDS"},
{"field": "keyword", "value": "mechanical ventilation"}
],
"year_from": "2020",
"limit": 20
}
📡 SSE 流式协议
流式接口(
/ask_stream、/expert_stream、/polish)以标准 Server-Sent Events 格式推送,每行格式为:event: <事件名>
data: <JSON字符串>
JavaScript 接入示例
const res = await fetch('https://traumadatacenter.com/ai/api/ask_stream', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'PRIME_你的密钥'
},
body: JSON.stringify({ question: 'ARDS的最新治疗进展' })
});
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value);
const lines = buffer.split('\n');
buffer = lines.pop(); // 保留未完成的行
let eventName = '';
for (const line of lines) {
if (line.startsWith('event: ')) eventName = line.slice(7);
if (line.startsWith('data: ')) {
const data = JSON.parse(line.slice(6));
if (eventName === 'answer_chunk') process.stdout.write(data.text);
if (eventName === 'done') console.log('\n[完成]');
}
}
}
💻 代码示例
Python — 同步问答
import requests
response = requests.post(
"https://traumadatacenter.com/ai/api/ask",
headers={
"X-API-Key": "PRIME_你的密钥",
"Content-Type": "application/json"
},
json={
"question": "脓毒症集束化治疗的最新指南推荐",
"date_from": "2021",
"max_refs": 8
}
)
data = response.json()
print(data["answer"])
for ref in data.get("references", []):
print(f"[{ref['pmid']}] {ref['title']}")
Python — 引用核查
import requests
res = requests.post(
"https://traumadatacenter.com/ai/api/factcheck_verify",
headers={"X-API-Key": "PRIME_你的密钥"},
json={
"sentence": "该研究显示低潮气量通气将死亡率降低了15%",
"pmid": "10793162"
}
)
result = res.json()
status = "✅ 一致" if result["consistent"] else "❌ 不一致"
print(status, result["reason"])
if result.get("suggestion"):
print("建议修改为:", result["suggestion"])
curl — 检查 Token 余额(通过错误码判断)
# 余额充足时正常返回;余额不足时返回 403 + insufficient_balance
curl -s -X POST https://traumadatacenter.com/ai/api/ask \
-H "X-API-Key: PRIME_你的密钥" \
-H "Content-Type: application/json" \
-d '{"question":"test"}' | python3 -m json.tool